简体   繁体   中英

Error while declaration of ‘wxDECLARE_EVENT_TABLE’

I have started developing with wxWidget C++ GUI library In Ubuntu 12.04 LTS.

I have downloaded and installed all the required library but while compiling the hello world program I am getting the error as

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

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

2> Removed wx from starting of all the macros.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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