// NamedStudent - this program demonstrates how adding // arguments to the constructor makes // for a more realistic class #include #include #include // Student class Student { public: Student(char *pszName, int nID) { // save off the person's name: // allocate from the heap the same // size string as that passed int nLength = strlen(pszName); this->pszName = new char[nLength]; // now copy the name passed into the // newly allocated buffer strcpy(this->pszName, pszName); // finally save off the student id this->nID = nID; } ~Student() { delete pszName; pszName = 0; } protected: char* pszName; int nID; }; int main(int nArgs, char* pszArg[]) { Student s("Stephen Davis", 1234); Student* pS = new Student("Kinsey Davis", 5678); cout << "this is output\n"; return 0; }