int main() { Base *p = new Derived; delete p; return 0; }
I have some confusion, why deleting p here won\'t delete the derived object ? Is
You should declare a virtual destructor:
class Base { //etc... virtual ~Base(); }; class Derived { //etc... virtual ~Derived(); }; Base* p = new Derived(); delete p;
(Of course many things are missing above, including constructors)