C++ function-pointer and inheritance
- by pingvinus
In parent class I have function, that operates under an array of functions, declared in child-class, number of functions for every child-class may vary. But since every function uses some object-variables, I can't declare them as static.
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;
this->fs = new func[1];
fs[0] = &B::f;
}
int f() {
return smth + 1;
}
};
But, obviously it doesn't work. Any suggestions?