Search code examples
c++qtvtableundefined-reference

'undefined reference to vtable' for abstract class (Qt)


I'm writing a library for parsing expressions into a tree structure and I have an abstract type QCExpressionNode as my base class. It looks like this:

#ifndef QCEXPRESSIONNODE_H
#define QCEXPRESSIONNODE_H

#include <QString>

class QCExpressionNode
{
public:
    virtual ~QCExpressionNode() {}

    virtual float evaluate(float* x) = 0;
    virtual bool containsVariable() = 0;
    virtual QString infixNotation() = 0;
};

Q_DECLARE_INTERFACE(QCExpressionNode, "org.nathanmoos.qcalc.libexprtree-qt.QCExpressionNode/0.1")

#endif // QCEXPRESSIONNODE_H

When I compile some tests (another project in QtCreator) that work on subclasses (QCConstantNode, QCVariableNode, QCBinaryOperatorNode, and so on), the linker gives me a 'undefined reference to vtable' error for QCExpressionNode. What am I doing wrong?


Solution

  • #include <QtPlugin>, then the file should compile just fine. Q_DECLARE_INTERFACE is declared in QtPlugin.

    By the way: it's quite unusual to compile header files by themselves and it's unusual to have include guards outside header files.