2013-07-25 31 views
2

我似乎遇到了我正在处理的wxWidgets项目的问题。我不断收到一个不涉及任何虚函数的类的vtable链接器错误。我想知道是否有人能够解释这个问题,因为根据我的理解,不应该使用虚拟函数的虚拟课堂。当有人忘记定义解构器时,我所见过的大多数类似的主题都会发生,但我确定解构器是正确定义的。错误可以在下面看到。从GUIFrame.h链接器错误对vtable的undefined引用

class PlanWindow : public wxWindow 
{ 
    DECLARE_EVENT_TABLE() 

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

     ~PlanWindow(); 

     void GetLocationList(int RetCode); 

     wxListBox *PlanList; 
}; 

||=== 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.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 
    { 

    } 
} 

任何帮助都将是巨大的。错误发生在构造器和析构器定义处。

+0

已经有一个正确的答案,但我只想提一提你总是在你的wxWindow派生类中有虚函数,它的dtor是虚拟的,因为它在'wxWindow'中是虚拟的。 –

回答

3

您还需要cpp文件执行使用BEGIN_EVENT_TABLE/END_EVENT_TABLE声明的事件表。一个例子;

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

哇。我知道这是我正在做的事情。没想到它是那么愚蠢。非常感谢。 =] – user2619631