home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ for Dummies (3rd Edition)
/
C_FD.iso
/
CHAP14
/
CHAP14_3.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-09-02
|
721b
|
34 lines
// Chap14_3.cpp
// this version doesn't work because of lack of a copy constructor
#include <iostream.h>
#include <string.h>
class Person
{
public:
Person(char *pN)
{
cout << "Constructing " << pN << "\n";
pName = new char[strlen(pN) + 1];
if (pName != 0)
{
strcpy(pName, pN);
}
}
~Person()
{
cout << "Destructing " << pName << "\n";
//letÆs wipe out the name just for the heck of it
pName[0] = '\0';
delete pName;
}
protected:
char *pName;
};
int main()
{
Person p1("Randy");
Person p2 = p1; //invoke the copy constructor...
return 0; //...equivalent to Person p2(p1);
}