Skip to main content
gamedev.net
🔒 Locked

delete derived class with base class pointer

Started by hululu Jan 5, 2004 at 1:05 PM 1 replies 500+ views
Original Post
hululu
hululu
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²
---accelerate your pc with 9.81 m/s²
antareus
antareus
Mark the base class destructor virtual.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
hululu
hululu
wow that''s all???

thanks

accelerate your pc with 9.81 m/s²
---accelerate your pc with 9.81 m/s²

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.