我有一个接口类,但我希望所有派生类都实现虚拟析构函数:
// Interface.h
class Interface {
virtual ~Interface() = 0;
};
Interface::~Interface() = default;
问题是,在这种情况下,由于符号重复,我有一个链接器错误。
我可以将定义放在.cpp
文件中,但我想知道是否有更优雅的解决方案?
您可以之前添加内联。根据http://en.cppreference.com/w/cpp/language/destructor这个语法是可以的:
decl-specifier-seq(optional) ~ class_name () = default;
decl-specifier-seq - friend, inline, virtual, or nothing (no return type)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句