1

I want to inherit QObject and another class and got an error: undefined reference for `vtable for EduGraph' I've read some threads about it and have fixed the sequence of the inherited classes in the class definition, but it haven't solved the problem.

class EduGraph : public QObject, public Graph<Vertex<ENode, EEdge>*> {
private:
    std::list<Vertex<ENode, EEdge>*>::iterator firstSel;
    std::list<Vertex<ENode, EEdge>*>::iterator secSel;
public:

Q_OBJECT

    EduGraph() : firstSel(0), secSel(0) {}
    ~EduGraph();

    void NewNode(const QPoint& p);
    void RemoveNode();
    void Associate();
    void Dissociate();

signals:
    void VertexSelected();
    void VertexDeSelected();
};
4

1 回答 1

2
`Undefined reference to `vtable for...'` 

is usually a sign of unimplemented virtual function. Make sure you have implemented (defined) the corresponding virtual functions you inherited from the base classes.

For example this will give you the same error because the print method in B is not implemented.

class A {
public:
    virtual void print() = 0;
};

class B : public A{
public:
    void print();
};

int main()
{
    B b;
}
于 2013-03-30T15:05:10.303 回答