update:
this bug in wxwidgets. has been fixed in wxwidgets 3.1.1, if you're using c++11 compatible compiler.
i'm trying dynamically bind event handler event in wxwidgets. unfortunately if derived class protected doesn't seem work.
minimal example:
// test.h class test : protected wxframe { public: test(); private: void sizing(wxsizeevent& event); }; // test.cpp test::test() { bind(wxevt_sizing, &test::sizing, this); } void test::sizing(wxsizeevent& event) { }
that unfortunately doesn't seem work , nets following error on visual studio 2015 update 3:
wxwidgets\include\wx/meta/convertible.h(31): error c2243: 'type cast': conversion 'test *' 'wxevthandler *' exists, inaccessible wxwidgets\include\wx/event.h(335): note: see reference class template instantiation 'wxconvertibleto<class,wxevthandler>' being compiled [ class=test ] wxwidgets\include\wx/event.h(3568): note: see reference class template instantiation 'wxeventfunctormethod<eventtag,test,eventarg,eventhandler>' being compiled [ eventtag=wxeventtypetag<wxsizeevent>, eventarg=wxsizeevent, eventhandler=test ] test.cpp(78): note: see reference function template instantiation 'void wxevthandler::bind<wxeventtypetag<wxsizeevent>,test,wxsizeevent,test>(const eventtag &,void (__cdecl test::* )(eventarg &),eventhandler *,int,int,wxobject *)' being compiled [ eventtag=wxeventtypetag<wxsizeevent>, eventarg=wxsizeevent, eventhandler=test ]
changing inheritance public makes work:
class test : public wxframe
- why conversion inaccessible when inheritance protected?
- i not wish expose wxframe world, classes derive test class. how can while still being able dynamically bind event handler?
you work around using following:
bind(wxevt_sizing, std::bind(&test::sizing, this, std::placeholders::_1));
minimal sample compiles:
#include <wx/wx.h> #include <functional> using namespace std::placeholders; class test : protected wxframe { public: test(); private: void sizing(wxsizeevent& event); }; test::test() { bind(wxevt_sizing, std::bind(&test::sizing, this, _1)); } void test::sizing(wxsizeevent& event) { } class myapp: public wxapp { public: virtual bool oninit(); }; class myframe: public wxframe { public: myframe(const wxstring& title, const wxpoint& pos, const wxsize& size); private: }; wximplement_app(myapp); bool myapp::oninit() { myframe *frame = new myframe( "", wxpoint(50, 50), wxsize(450, 340) ); frame->show( true ); return true; } myframe::myframe(const wxstring& title, const wxpoint& pos, const wxsize& size) : wxframe(null, wxid_any, title, pos, size) { test* test = new test(); }
Comments
Post a Comment