c++ undefined reference to vtable

I Just encountered the same problem, but my problem was that I had not written the destructor code in my .cpp file.

class.h:

class MyClass {
public:
    MyClass();
    virtual ~MyClass();
};

class.cpp:

MyClass::MyClass() {}

It just gave me the vtable error message, and implementing the (empty) destructor solved the problem.

[Edit] Thus, the corrected class file looks like this:

MyClass::MyClass() {}
MyClass::~MyClass() {}

Leave a Comment