Virtual Default Destructors in C++

前端 未结 4 1602
旧巷少年郎
旧巷少年郎 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:29

    One small change from what others have already answered:

    Instead of

    virtual void ~criterion() = 0;
    

    the required version is:

        virtual ~criterion() {}  //Note: Removed void as destructors not allowed 
                                 //  a return type
    

    To know more about virtual destructor have a look at this link from FAQ When should my destructor be virtual?

提交回复
热议问题