I\'m trying to compile the following simple C++ code using Clang-3.5:
test.h:
class A
{
public:
A();
virtual ~A() = 0;
};
I ended up implementing a trivial virtual destructor, rather than leaving it pure virtual.
So instead of
class A {
public:
virtual ~A() = 0;
};
I use
class A {
public:
virtual ~A();
};
Then implement the trivial destructor in a .cpp file:
A::~A()
{}
This effectively pins the vtable to the .cpp file, instead of outputting it in multiple translation units (objects), and successfully avoids the -Wweak-vtables warning.
As a side effect of explicitly declaring the destructor you no longer get the default copy and move operations. See https://stackoverflow.com/a/29288300/954 for an example where they are redeclared.