在C++ 11中正确放置默认的纯虚析构函数

Ale*_*lex 2 c++ virtual-destructor c++11

我有一个接口类,但我希望所有派生类都实现虚拟析构函数:

// Interface.h
class Interface {
    virtual ~Interface() = 0;
};

Interface::~Interface() = default;
Run Code Online (Sandbox Code Playgroud)

问题是在这种情况下,由于重复的符号,我有一个链接器错误.

我可以将定义放在.cpp文件中,但我想知道是否有更优雅的解决方案?

Ser*_*kov 5

您可以在之前添加内联.根据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) 
Run Code Online (Sandbox Code Playgroud)