I have an generic math-method, that operates under a set of functions (with a lot of variables and states, so it can't be static). I've implemented method in parent class and I want to declare a different set of functions in every child-class.
I've try to do something like this:
class A {
public:
typedef int (A::*func)();
func * fs;
void f() { /*call functions from this->fs*/ }
};
class B : public A {
public:
int smth;
B(int smth) {
this->smth = smth; //user-provided variables
//there may be a lot of functions with same interface
this->fs = new func[1];
fs[0] = &B::f;
}
int f() {
return smth + 1;
}
};
It fails with this error: error C2440: '=' : cannot convert from 'int (__thiscall B::* )(void)' to 'A::func'
Or "IntelliSense: a pointer to a bound function may only be used to call the function" if I try to use &this->f;