oop - C++ function pointers and classes -


say have:

void render(void(*call)()) {     d3ddevice->beginscene();     call();     d3ddevice->endscene();     d3ddevice->present(0,0,0,0); } 

this fine long function want use render function or static member function:

render(mainmenurender); render(mainmenu::render); 

however, want able use class method since in cases rendering function want access member variables, , id rather not make class instance global, e.g.

render(mainmenu->render); 

however have no idea how this, , still allow functions , static member functions used.

there lot of ways skin cat, including templates. favorite boost.function i've found flexible in long run. read on boost.bind binding member functions many other tricks.

it this:

#include <boost/bind.hpp> #include <boost/function.hpp>  void render(boost::function0<void> call) {     // before... }  render(boost::bind(&mainmenu::render, mymainmenuinstance)); 

Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -