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

  1. // Chap12_5.cpp (This version works as compared with 12_4)
  2. #include <iostream.h>
  3. #include <string.h>
  4.  
  5. class StudentId
  6. {
  7.   public:
  8.    StudentId(int id = 0)
  9.    {
  10.       value = id;
  11.       cout << "Assigning student id " << value << "\n";
  12.    }
  13.  
  14.   protected:
  15.    int value;
  16. };
  17.  
  18. class Student
  19. {
  20.   public:
  21.    Student(char *pName  = "no name", int ssId = 0) : id(ssId)
  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.  
  33. int main()
  34. {
  35.    Student s("Randy", 1234);
  36.    cout << "This message from main\n";
  37.    return 0;
  38. }
  39.