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

前端 未结 7 2428
有刺的猬
有刺的猬 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:26

    It's more or less a bug in the compiler. Note that in more recent versions of the compiler this warning does not get thrown (at least in 4.3 it doesn't). Having the destructor be protected and non-virtual is completely legitimate in your case.

    See here for an excellent article by Herb Sutter on the subject. From the article:

    Guideline #4: A base class destructor should be either public and virtual, or protected and nonvirtual.

提交回复
热议问题