2013-07-25 32 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