Alex Alex - 11 months ago 75
C++ Question

Proper placement for the default pure virtual destructor in C++11

I have an interface class but I want all derived classes to implement the virtual destructor:

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

Interface::~Interface() = default;

The problem is that in this case I have a linker error because of duplicated symbols.

I can place the definition in
file but I'd like to know if there is more elegant solution?

Answer Source

You can add inline before. According to this syntax is OK:

decl-specifier-seq(optional) ~ class_name () = default;

decl-specifier-seq  -   friend, inline, virtual, or nothing (no return type) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download