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

  1. // Chap12_4.cpp (Note that this program doesn't work)
  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)
  22.    {
  23.       cout << "Constructing student " << pName << "\n";
  24.       strncpy(name, pName, sizeof(name));
  25.       name[sizeof(name) - 1]  = '\0';
  26.       //donÆt try this at home kids. It doesnÆt work
  27.       StudentId id(ssId);    //construct a student id
  28.    }
  29.   protected:
  30.    char  name[40];
  31.    StudentId id;
  32. };
  33.  
  34. int main()
  35. {
  36.    Student s("Randy", 1234);
  37.    cout << "This message from main\n";
  38.    return 0;
  39. }
  40.