开始在现有代码库上使用 PC-Lint(恐惧和恐惧)。
它提示的一件事是:
class IBatch
{
public:
virtual void StartBatch() =0;
virtual int CommitBatch() =0;
};
当另一个类从中派生以像接口(interface)一样使用它时
base class 'IBatch' has no destructor
所以,问题是:当你像上面那样创建 Interface 类时,你总是包含一个虚拟析构函数吗?为什么? (是样式错误还是编码错误?)
编辑:应该说我不希望或不希望 IBatch 的 user 破坏,他们只是服务的消费者,通过这个接口(interface)到某个外部实现类(如果那样的话有所作为)
最佳答案
A base class destructor should be either public and virtual, or protected and nonvirtual.
(Herb Sutter, Guru of the Week #18: "Virtuality")
https://stackoverflow.com/questions/2691611/