Virtual Default Destructors in C++

前端 未结 4 1607
旧巷少年郎
旧巷少年郎 2020-12-24 08:02

I\'ve got a large set of inherited classes (criteria) which inherit from a base class (criterion). Here\'s criterion\'s code

class criterion
{
p         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-24 08:22

    Yes - the base class needs a virtual destructor, even if it's empty. If that is not done, then when something delete's a derived object through a base pointer/reference, the derived object's member objects will not get a chance to destroy themselves properly.

    Derived classes do not need to declare or define their own destructor unless they need something other than default destructor behavior.

提交回复
热议问题