home *** CD-ROM | disk | FTP | other *** search
- // ex09019.cpp
- // Virtual destructor
-
- #include <iostream.h>
- #include <string.h>
-
- class Company {
- char *name;
- public:
- Company(char *s)
- { name = new char[strlen(s+1)]; strcpy(name, s); }
- virtual ~Company()
- { cout << "\nC destructor"; delete name;}
- void org_name() { cout << name; }
- };
-
- class Division : public Company {
- char *manager;
- public:
- Division(char *s, char *mgr) : Company(s)
- {manager=new char[strlen(mgr+1)]; strcpy(manager, mgr);}
- ~Division() { cout << "\nD destructor"; delete manager;}
- };
-
- main()
- {
- Company *companies[3];
- companies[0] = new Company("Bilbo Software, Inc.");
- companies[1] = new Division("Vert Apps", "Ron Herold");
- companies[2] = new Division("Horiz Apps", "Bob Young");
- for (int i = 0; i < 3; i++) {
- // ....... process the company objects
- delete companies[i]; // always right destructor
- }
- }