Destructors for C++ Interface-like classes

前端 未结 6 1011
甜味超标
甜味超标 2020-12-30 23:20

Starting to use PC-Lint on an existing code base (fear and trepidation).

One thing that it complains about is the following:

 class IBatch
 {
 public         


        
6条回答
  •  盖世英雄少女心
    2020-12-31 00:14

    If there are virtual functions, there needs to be a virtual destructor. Always. It does not matter that it's only an interface class -- it still needs the virtual destructor.

    Either that, or it needs a protected nonvirtual destructor. But then you cannot delete the object using the interface pointer.

提交回复
热议问题