A alpha;
alpha.a = 10;
Call((alpha.Func)());
Assuming Call takes a void function pointer as a parameter, does anyone know the syntax for this, with different class types?
A alpha;
alpha.a = 10;
Call((alpha.Func)());
Assuming Call takes a void function pointer as a parameter, does anyone know the syntax for this, with different class types?
Quote:Original post by nimrand
The problem is that non-static member functions work differently than regular functions, so they are not supported by C++ function pointers.
classname c;void ( classname::*mthdptr )();mthdptr = classname::test; // assign method to pointer( c.*mthdptr )(); // call method
Ok, thanks.
i cant get it to work with different object types though :/, how can i do this?
the reason i ask is that the current method i use involves inheriting an abstract base class, but since all this base class consists of is one function and 3 overloaded functions, i want to cut it out and replace with a function with 3 function pointer arguments... :D
Thanks again.
Quote:Original post by GenjixI think you could do that with templates(untested):Ok, thanks.
i cant get it to work with different object types though :/, how can i do this?
the reason i ask is that the current method i use involves inheriting an abstract base class, but since all this base class consists of is one function and 3 overloaded functions, i want to cut it out and replace with a function with 3 function pointer arguments... :D
Thanks again.
template<class Class>void call(void (Class::*method)(), Class object) { (object.*method())();}
template<class Class, typename Arguments>void call(void (Class::*method)(Arguments), Class object, Arguments args) { (object.*method(Arguments))(args);}
class Alpha{ //... void func(void); //...};template <typename T>Call(T & t){ t.func();}
Thanks for the solution, didnt think oof templates :P.
jflanglois : what i WAS doing was every class that used the function, inherited a base class with the function as a member, and the functions that would be passed in here were abstracted (meant to be overriden, and any calls to them were meant to be to the parent class).