Can the default destructor be generated as a virtual destructor automatically?

前端 未结 7 1544
轮回少年
轮回少年 2021-01-31 07:30

Can the default destructor be generated as a virtual destructor automatically?

If I define a base class but no default destructor, is there a default virtual destructor

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 07:56

    Uri and Michael are right -- I'll just add that if what's bugging you is having to touch two files to declare and define the destructor, it's perfectly all right to define a minimal one inline in the header:

    class MyClass
    {
       // define basic destructor right here
       virtual ~MyClass(){}
    
       // but these functions can be defined in a different file
       void FuncA();
       int FuncB(int etc);
    }
    

提交回复
热议问题