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 .cpp
file but I'd like to know if there is more elegant solution?
You can add inline before. According to http://en.cppreference.com/w/cpp/language/destructor this syntax is OK:
decl-specifier-seq(optional) ~ class_name () = default;
decl-specifier-seq - friend, inline, virtual, or nothing (no return type)