home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX09018.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  881 b   |  35 lines

  1. // ex09018.cpp
  2. // Base and derived destructors
  3.  
  4. #include <iostream.h>
  5. #include <string.h>
  6.  
  7. class Company    {
  8.     char *name;
  9. public:
  10.     Company(char *s)
  11.         { name = new char[strlen(s+1)]; strcpy(name, s); }
  12.     ~Company() { cout << "\nC destructor"; delete name; }
  13.     void org_name() { cout << name; }
  14. };
  15.  
  16. class Division : public Company    {
  17.     char *manager;
  18. public:
  19.     Division(char *s, char *mgr) : Company(s) 
  20.     {manager=new char[strlen(mgr+1)]; strcpy(manager, mgr);}
  21.     ~Division() {cout << "\nD destructor"; delete manager;}
  22. };
  23.  
  24. main()
  25. {
  26.     Company *companies[3]; 
  27.     companies[0] = new Company("Bilbo Software, Inc.");
  28.     companies[1] = new Division("Vert Apps", "Ron Herold");
  29.     companies[2] = new Division("Horiz Apps", "Bob Young");
  30.     for (int i = 0; i < 3; i++)    {
  31.         // ....... process the company objects
  32.         delete companies[i]; // not always right destructor
  33.     }
  34. }
  35.