home *** CD-ROM | disk | FTP | other *** search
- #if 0
- From: Bhatia
- Subject: Virtual destructor bug
- Status: Not a compiler bug. Needs X::X(X&) and operator=(X&) defined.
- #endif
-
-
- #include <stdio.h>
- #include <string.h>
-
- class Company
- {
- char *name;
- public:
- Company(char *s) {name=new char[strlen(s+1)]; strcpy(name,s);}
- virtual ~Company() { printf("\nC destructor"); delete name;}
- void org_name() { printf("%s",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() {printf("\nD destructor"); delete manager;}
- };
-
- void main()
- {
- Company *companies[3];
- companies[0] = new Company("Bilbo Sofware, Inc.");
- companies[1] = new Division("Vert Apps", "Ron Herold");
- companies[3] = new Division("Horiz Apps", "Bob Young");
- for( int i=0;i<3;i++)
- delete companies[i];
- };
-
- // Compiled with 2.18
- // Output from the above file
-
- //C Destructor
- //
- //Heap is corrupted
-
-