简体   繁体   English

声明“ wxDECLARE_EVENT_TABLE”时出错

[英]Error while declaration of ‘wxDECLARE_EVENT_TABLE’

I have started developing with wxWidget C++ GUI library In Ubuntu 12.04 LTS. 我已经开始在Ubuntu 12.04 LTS中使用wxWidget C ++ GUI库进行开发。

I have downloaded and installed all the required library but while compiling the hello world program I am getting the error as 我已经下载并安装了所有必需的库,但是在编译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 Declaration 类声明

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);
};

Data Table Declaration 数据表声明

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);

Compilation command 编译命令

g++ wx.cpp wx-config --cxxflags wx-config --libs g ++ wx.cpp wx-config --cxxflags wx-config --libs

How to solve this issue or How to use the event Data Table? 如何解决此问题或如何使用事件数据表?

Edit: 编辑:

Headers 标头

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
   #include <wx/wx.h>
#endif
wxDECLARE_EVENT_TABLE(MyFram, wxFrame);

is incorrect. 是不正确的。 It should be: 它应该是:

wxDECLARE_EVENT_TABLE();

(it doesn't take any arguments). (不带任何参数)。

You should be getting an error about that just before the error you mentioned in the question. 您应该在问题中提到的错误之前就收到有关此错误的信息。

Because of the extra arguments, the macro is not expanded during the preprocessing phase. 由于存在额外的参数,因此宏在预处理阶段不会扩展。 Later on during compilation, the compiler assumes you want to declare a member function and that's where your error comes from. 稍后在编译过程中,编译器假定您要声明一个成员函数,这就是错误的出处。

Solved By Correcting the following things. 通过纠正以下问题解决。

1> Followed the answer of @bogdan 1>跟随@bogdan的回答

2> Removed wx from starting of all the macros. 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);

It appears that you didn't even get the definition of the macro into the program. 看来您甚至都没有将宏的定义添加到程序中。 Were the program headers and libraries linked and included correctly? 程序头文件和库是否已正确链接和包含?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM