[英]Error while declaration of ‘wxDECLARE_EVENT_TABLE’
我已經開始在Ubuntu 12.04 LTS中使用wxWidget C ++ GUI庫進行開發。
我已經下載並安裝了所有必需的庫,但是在編譯hello world程序時卻遇到了以下錯誤:
error: ISO C++ forbids declaration of ‘wxDECLARE_EVENT_TABLE’ with no type [-fpermissive]
wxDECLARE_EVENT_TABLE();
^
In file included from /usr/include/wx-2.8/wx/wx.h:25:0,
from wx.cpp:3:
/usr/include/wx-2.8/wx/event.h:96:5: error: expected constructor, destructor, or type conversion before ‘wxEventTableEntry’
wxEventTableEntry(type, winid, idLast, fn, obj)
.....
類聲明
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE(MyFram, wxFrame);
};
數據表聲明
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Hello, MyFrame::OnHello)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
wxEND_EVENT_TABLE()
wxIMPLEMENT_APP(MyApp);
編譯命令
g ++ wx.cpp
wx-config --cxxflags
wx-config --libs
如何解決此問題或如何使用事件數據表?
編輯:
標頭
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
wxDECLARE_EVENT_TABLE(MyFram, wxFrame);
是不正確的。 它應該是:
wxDECLARE_EVENT_TABLE();
(不帶任何參數)。
您應該在問題中提到的錯誤之前就收到有關此錯誤的信息。
由於存在額外的參數,因此宏在預處理階段不會擴展。 稍后在編譯過程中,編譯器假定您要聲明一個成員函數,這就是錯誤的出處。
通過糾正以下問題解決。
1>跟隨@bogdan的回答
2>從所有宏的開頭中刪除了wx。
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Hello, MyFrame::OnHello)
EVT_MENU(wxID_EXIT, MyFrame::OnExit)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp);
看來您甚至都沒有將宏的定義添加到程序中。 程序頭文件和庫是否已正確鏈接和包含?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.