声明“wxDECLARE_EVENT_TABLE”时出错
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声明
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);
};
数据Table声明
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
如何解决这个问题或如何使用事件数据Table?
编辑:
Headers
#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);
我已经开始使用 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声明
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);
};
数据Table声明
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
如何解决这个问题或如何使用事件数据Table?
编辑:
Headers
#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);