// FalseStudentId - the following attempts to create // the student id data member using // a non-default constructor. #include #include #include class StudentId { public: StudentId(int nId = 0) { this->nId = nId; cout << "Assigning student id " << nId << "\n"; } ~StudentId() { cout << "Destructing student id " << nId << "\n"; } protected: int nId; }; class Student { public: // constructor - create an object with a specified // name and student id Student(char* pszName = "no name", int ssId = 0) { cout << "Constructing student " << pszName << "\n"; this->pszName = new char[strlen(pszName) + 1]; strcpy(this->pszName, pszName); //don't try this at home kids. It doesn't work StudentId id(ssId); //construct a student id } ~Student() { cout << "Destructing student " << this->pszName << "\n"; delete this->pszName; pszName = 0; } protected: char* pszName; StudentId id; }; int main() { Student s("Randy", 1234); cout << "This message from main\n"; return 0; }