ch14_4.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //**********************
- //** ch14_4.cpp **
- //**********************
- #include <iostream.h>
- #include <string.h>
- class Person{
- public:
- Person(char* pN);
- Person(Person& p);
- ~Person();
- protected:
- char* pName;
- };
- Person::Person(char* pN)
- {
- cout <<"Constructing " <<pN <<endl;
- pName=new char[strlen(pN)+1];
- if(pName!=0)
- strcpy(pName,pN);
- }
- Person::Person(Person& p)
- {
- cout <<"Copying " <<p.pName <<" into its own blockn"; pName=new char[strlen(p.pName)+1];
- if(pName!=0)
- strcpy(pName,p.pName);
- }
- Person::~Person()
- {
- cout <<"Destructing " <<pName <<endl;
- pName[0]=' ';
- delete pName;
- }
- void main()
- {
- Person p1("Randy");
- Person p2=p1; //即Person p2(p1);
- }