GNU compiler warning “class has virtual functions but non-virtual destructor”

前端 未结 7 2377
有刺的猬
有刺的猬 2020-12-13 06:08

I have defined an interface in C++, i.e. a class containing only pure virtual functions.

I want to explicitly forbid users of the interface to delete the object thro

7条回答
  •  醉梦人生
    2020-12-13 06:21

    If you had code in one of ITest's methods that tried to delete itself (a bad idea, but legal), the derived class's destructor wouldn't be called. You should still make your destructor virtual, even if you never intend to delete a derived instance via a base-class pointer.

提交回复
热议问题