This topic is now archived and is closed to further replies.


delete derived class with base class pointer

Recommended Posts

hi when i create a derived class and store the pointer of the new created class in a base class pointer, can i delete the class with this pointer? here some code to show what i mean: class BaseClass { ... }; class DerivedClass : public BaseClass { ... }; BaseClass *pBaseClass = new DerivedClass //do something delete BaseClass; after some tests i found out that only the destructor of A is called after deleting this pointer. does this mean only a part (the BaseClass part) of class B is deleted? is there another way to delete such pointer without cast the pointer back? accelerate your pc with 9.81 m/s²

Share this post

Link to post
Share on other sites