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
Post a Comment