// DefaultStudentId - create a student object using the // the next available student ID #include #include #include // StudentId int nNextStudentId = 0; class StudentId { public: StudentId() { value = ++nNextStudentId; cout << "Assigning student id " << value << "\n"; } ~StudentId() { cout << "Destructing student id " << value << "\n"; } protected: int value; }; // Student class Student { public: // constructor - create a student with the name // supplied (use default of "no name") Student(char *pszName = "no name") { cout << "Constructing student " << pszName << "\n"; // copy the string passed to the local member this->pszName = new char[strlen(pszName) + 1]; strcpy(this->pszName, pszName); } ~Student() { cout << "Destructing student " << pszName << "\n"; delete pszName; pszName = 0; } protected: char* pszName; StudentId id; }; int main(int nArgs, char* pszArg[]) { Student s("Randy"); return 0; }