1

When linking e.g. with GCC on linux I get:

undefined reference to `vtable for MyClass'

Problem is, the MyClass ancestors have about 100 pure virtual methods, and I don't know which of them isn't defined. Do I really have to go through all of them to find out?

Yaron Cohen-Tal
  • 2,005
  • 1
  • 15
  • 26

1 Answers1

3

As mentioned down on the link from @Jonas comment, the message "undefined reference to vtable" only happens if the first declared virtual method is not defined: https://stackoverflow.com/a/28458010/1274747

And as I tried just now, this is really the case: If the first declared overridden virtual method is not defined, I get the vtable error. If some other function down the line is not defined, I get undefined reference error of that particular method.

Example:

struct base
{
    virtual ~base() {}
    virtual int func1() = 0;
    virtual int func2() = 0;
};

struct derived: base
{
    virtual int func1();
    virtual int func2();
};

// switch the comment to define one or the other
int derived::func1() // undefined reference to `derived::func2()'
// int derived::func2() // "undefined reference to `vtable for derived'"
{
    return 5;
}

int main()
{
    derived d;
    return 0;
}

That means, check the first virtual function declared in the derived class (it might also be a virtual destructor).

Community
  • 1
  • 1
EmDroid
  • 5,918
  • 18
  • 18