Given the following class, which simply maps an internal functor f to a function to be run later:
class A {
private:
int (A::*f)(int);
int foo(int x) { return x; }
int bar(int x) { return x*2; }
public:
explicit A(bool foo=true) { f = foo ? &A::foo : &A::bar; }
int run(int x) { return (this->*f)(x); }
};
Now say I have another class, B:
class B {
public:
int foo(int) { return x*x; }
};
And function foo:
int foo(int x) { return 0; }
I know it is not possible to have A assign and run B::foo or foo as their prototypes differ: int (A::*)(int) vs int (B::*)(int) vs int (*)(int).
What I am asking, is their any way to templatize A::f such that it could take any of them?
I am not exactly sure what you are trying to achieve, but you may want to look into: