Undefined reference to vtable

前端 未结 16 2136
死守一世寂寞
死守一世寂寞 2020-11-21 20:30

When building my C++ program, I\'m getting the error message

undefined reference to \'vtable...

What is the cause of this probl

相关标签:
16条回答
  • 2020-11-21 21:07
    • Are you sure that CDasherComponent has a body for the destructor? It's definitely not here - the question is if it is in the .cc file.
    • From a style perspective, CDasherModule should explicitly define its destructor virtual.
    • It looks like CGameModule has an extra } at the end (after the }; // for the class).
    • Is CGameModule being linked against the libraries that define CDasherModule and CDasherComponent?
    0 讨论(0)
  • 2020-11-21 21:09

    For what it is worth, forgetting a body on a virtual destructor generates the following:

    undefined reference to `vtable for CYourClass'.

    I am adding a note because the error message is deceptive. (This was with gcc version 4.6.3.)

    0 讨论(0)
  • 2020-11-21 21:14

    I simply got this error because my .cpp file was not in the makefile.

    In general, if you forget to compile or link to the specific object file containing the definition, you will run into this error.

    0 讨论(0)
  • 2020-11-21 21:14

    In my case I'm using Qt and had defined a QObject subclass in a foo.cpp (not .h) file. The fix was to add #include "foo.moc" at the end of foo.cpp.

    0 讨论(0)
  • 2020-11-21 21:16

    If you are using Qt, try rerunning qmake. If this error is in the widget's class, qmake might have failed to notice that the ui class vtable should be regenerated. This fixed the issue for me.

    0 讨论(0)
  • 2020-11-21 21:21

    If all else fails, look for duplication. I was misdirected by the explicit initial reference to constructors and destructors until I read a reference in another post. It's any unresolved method. In my case, I thought I had replaced the declaration that used char *xml as the parameter with one using the unnecessarily troublesome const char *xml, but instead, I had created a new one and left the other one in place.

    0 讨论(0)
提交回复
热议问题