home *** CD-ROM | disk | FTP | other *** search
- // Chap15_2.cpp
- #include <iostream.h>
- #include <string.h>
- class Student
- {
- public:
- Student(char *pN)
- {
- cout << "Constructing " << pN << "\n";
- pName = new char[strlen(pN) + 1];
- if (pName != 0)
- {
- strcpy(pName, pN);
- }
- }
- //copy constructor allocates a new heap block
- Student(Student &s)
- {
- cout << "Copying " << s.pName << " into its own block\n";
- pName = new char[strlen(s.pName) + 1];
- if (pName != 0)
- {
- strcpy(pName, s.pName);
- }
- }
- ~Student()
- {
- cout << "Destructing " << pName << "\n";
- //letÆs wipe out the name just for the heck of it
- pName[0] = '\0';
- delete pName;
- }
- protected:
- char *pName;
- };
-
- void fn(Student)
- {
- // do nothing function
- }
-
- int main()
- {
- fn("Danny"); //what exactly are we calling here?
- return 0;
- }
-