声明'wxDECLARE_EVENT_TABLE'时出错

时间:2015-01-29 09:22:06

标签: c++ wxwidgets

我已经开始使用wxWidget C ++ GUI库在Ubuntu 12.04 LTS中进行开发。

我已下载并安装了所有必需的库,但在编译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

3 个答案:

答案 0 :(得分:1)

wxDECLARE_EVENT_TABLE(MyFram, wxFrame);

不正确。它应该是:

wxDECLARE_EVENT_TABLE();

(它没有任何参数)。

您应该在问题中提到的错误之前收到错误。

由于额外的参数,宏在预处理阶段不会展开。稍后在编译期间,编译器假定您要声明成员函数以及您的错误来自哪里。

答案 1 :(得分:1)

解决方法纠正以下事项。

1&GT;按照@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);

答案 2 :(得分:0)

看起来你甚至没有将宏的定义纳入程序。程序头和库是否正确链接和包含?