// // Virtual "constructor" and destructor // // // destructors most cases should be virtual: // class Base { public: virtual ~Base() { ... } }; class Der : public Base { public: virtual ~Der() { ... } }; void f() { // ... Base *bp = new Der; // ... delete bp; } // // there is no virtual constructor // but we can simulate it: // class Base { public: virtual Base* clone() { return new Base(*this); } }; class Der : public Base { public: virtual Der* clone() { return new Der(*this); } }; void f() { // ... for ( Base *bp = first; bp; bp = bp->next() ) { append( bp->clone() ); } }