Does “delete” work properly with polymorphism? [duplicate]
问题 This question already has answers here : Virtual destructor and undefined behavior (4 answers) Closed 6 years ago . BaseClass * p = new DerivedClass(); delete p; I know the 2nd line will call the destructor of the base class if it doesn't have a virtual destructor and that of the derived class if it does but will delete properly free the memory (let's say BaseClass 's object takes up 8 bytes of space and DerivedClass 's one 12 - will it free 8 or 12 bytes) and get rid of the object in either