struct MyApp { typedef MyApp CLASSNAME; Vector<String> top; Vector< Vector<String> > submenu; void Action(int top, int i) { /* some action */ } void SubMenu(Bar& bar, int top) { const Vector<String>& sm = submenu[top]; for(int i = 0; i < sm.GetCount(); i++) bar.Add(sm[i], THISBACK2(Action, top, i)); } void MainMenu(Bar& bar) { for(int i = 0; i < top.GetCount(); i++) bar.Add(top[i], THISBACK1(SubMenu, i)); } .... };
void SubMenu(Bar& bar, int a, int b) { for(int i = 0; i < 10; i++) bar.Add(AsString(i), THISBACK1(ShowNumber, i)); } void Menu(Bar& bar) { bar.Add("Enable numbers", THISBACK(EnableNumbers)) .Check(numbers_enabled); bar.Add(numbers_enabled, "Numbers", THISBACK2(SubMenu,1,2)); bar.Add("Exit", THISBACK(Exit)) .Key(K_CTRL_E); }
MSVC8: C:\upp\reference\Menu\menu.cpp(33) : error C2780: 'Callback callback2(Callback2<P1,P2>,T1 ,T2)' : expects 3 arguments - 4 provided C:\upp\uppsrc\Core/Callback.h(202) : see declaration of 'callback2' C:\upp\reference\Menu\menu.cpp(33) : error C2780: 'Callback callback2(R (__cdecl *)(A,B), T1,T2)' : expects 3 arguments - 4 provided C:\upp\uppsrc\Core/Callback.h(197) : see declaration of 'callback2' C:\upp\reference\Menu\menu.cpp(33) : error C2784: 'Callback callback2(const Object *,R (_ _thiscall O::* )(A,B) const,T1,T2)' : could not deduce template argument for 'R (__th iscall O::* )(A,B) const' from 'void (__thiscall App::* )(Bar &,int,int)' C:\upp\uppsrc\Core/Callback.h(181) : see declaration of 'callback2' C:\upp\reference\Menu\menu.cpp(33) : error C2784: 'Callback callback2(Object *,R (__thisc all O::* )(A,B),T1,T2)' : could not deduce template argument for 'R (__thiscall O::* )(A,B)' from 'void (__thiscall App::* )(Bar &,int,int)' C:\upp\uppsrc\Core/Callback.h(175) : see declaration of 'callback2' GCC(MinGW): C:\upp\reference\Menu\menu.cpp: In member function `void App::Menu(Bar&)': C:\upp\reference\Menu\menu.cpp:33: error: no matching function for call to `callback2(App * const, void (App::*)(Bar&, int, int), int, int)'
Quote: |
Despite this working for me now and most smaller applications wouldn't read their interfaces from a file at runtime anyways, I think it might be worth it to allow for a more "procedural" approach of menu creation for such situations - I haven't investigated the needed changes, so it could be too much work for the benifit. |
bar.Add("Dummy Item", Callback(nullptr));