【问题标题】:Linker Error undefined reference to vtable链接器错误未定义对 vtable 的引用
【发布时间】:2013-07-25 18:00:30
【问题描述】:

我正在处理的 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 中是虚拟的。

标签: c++ wxwidgets linker-errors vtable


【解决方案1】:

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

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

【讨论】:

  • 哇。我知道这是我在做的蠢事。没想到会这么傻。非常感谢。 =]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-03
  • 2010-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多