home *** CD-ROM | disk | FTP | other *** search
/ C++ for Dummies (3rd Edition) / C_FD.iso / CHAP12 / CHAP12_3.CPP < prev    next >
C/C++ Source or Header  |  1996-09-02  |  603b  |  37 lines

  1. // Chap12_3.cpp
  2. #include <iostream.h>
  3. #include <string.h>
  4.  
  5. int nextStudentId = 0;
  6. class StudentId
  7. {
  8.   public:
  9.    StudentId() 
  10.    {
  11.       value = ++nextStudentId;
  12.       cout << "Assigning student id " << value << "\n";
  13.    }
  14.   protected:
  15.    int value;
  16. };
  17.  
  18. class Student
  19. {
  20.   public:
  21.    Student(char *pName  = "no name")
  22.    {
  23.       cout << "Constructing student " << pName << "\n";
  24.       strncpy(name, pName, sizeof(name));
  25.       name[sizeof(name) - 1]  = '\0';
  26.    }
  27.   protected:
  28.    char  name[40];
  29.    StudentId id;
  30. };
  31.  
  32. int main()
  33. {
  34.    Student s("Randy");
  35.    return 0;
  36. }
  37.