链接器错误 undefined reference to vtable

3

我在处理一个wxWidgets项目时遇到了问题。我一直收到一个与任何虚函数无关的类的vtable链接器错误。我想知道是否有人能够解决这个问题,因为据我理解,不使用虚函数的类不应该有vtable。我看到的大多数类似主题都是因为某人忘记定义析构函数,但我相当确定析构函数已经正确定义了。下面可以看到错误信息。

||=== Hike Planner GUI, Debug ===|
obj\Debug\GUIFrame.o||In function `PlanWindow':|
E:\Projects\Hike Planner GUI\GUIFrame.cpp|76|undefined reference to `vtable for              PlanWindow'|
E:\Projects\Hike Planner GUI\GUIFrame.cpp|76|undefined reference to `vtable for PlanWindow'|
obj\Debug\GUIFrame.o||In function `~PlanWindow':|
E:\Projects\Hike Planner GUI\GUIFrame.cpp|81|undefined reference to `vtable for PlanWindow'|
E:\Projects\Hike Planner GUI\GUIFrame.cpp|81|undefined reference to `vtable for PlanWindow'|
E:\Projects\Hike Planner GUI\GUIFrame.cpp|81|undefined reference to `vtable for PlanWindow'|
||=== Build finished: 5 errors, 0 warnings ===|

来自GUIFrame.h的片段

class PlanWindow : public wxWindow
{
    DECLARE_EVENT_TABLE()

    public:
        PlanWindow(wxWindow* parent, wxWindowID id);

        ~PlanWindow();

        void GetLocationList(int RetCode);

        wxListBox *PlanList;
};

从GUIFrame.cpp中提取的代码段:

PlanWindow::PlanWindow(wxWindow* parent, wxWindowID id) : wxWindow(parent,id) 
{

}

PlanWindow::~PlanWindow()
{

}

void PlanWindow::GetLocationList(int RetCode)
{
    if(RetCode == DEST)
    {

    }
    else if(RetCode == TH)
    {

    }
    else if(RetCode == FREE)
    {

    }
    else
    {

    }
}

任何帮助都将是非常棒的。错误发生在构造函数和析构函数定义处。


已经有一个正确的答案了,但我想提一下,在您的wxWindow派生类中,您''总是''有虚函数,例如它的dtor是虚拟的,因为在wxWindow中它是虚拟的。 - VZ.
1个回答

3

您还需要在cpp文件中使用BEGIN_EVENT_TABLE/END_EVENT_TABLE实现所声明的事件表。以下是一个例子:

BEGIN_EVENT_TABLE(PlanWindow, wxWindow)
//  EVT_SIZE (PlanWindow::OnSize)       // Example size handler
END_EVENT_TABLE()

哇。我知道我做错了什么愚蠢的事情,但没想到会这么愚蠢。非常感谢。=] - user2619631

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接