Let's say there is an Object class, and then another Cat class that inherits Object. Next, there is a list of objects * (pointers). Then I create a new Cat and put it on the list. After some time, I want to delete all cats and delete delete for each member of the list. Does it call a Cat destructor?
Yes, if you marked the object destructor as virtual.
class Object { public: virtual ~Object(){} //make the base class destructor virtual }; class cat : public Object { public: virtual ~cat(){} // now this gets called when a pointer to Object that is a cat is destroyed }
If the object's destructor is virtual, yes.
, , - , . ++ FAQ.
, class Object ( ) , undefined, .
class Object