Hi suppose I have a code like this
// base class
class A {
public:
int CallMyFct(PtrToFCT what){
return what(10);
}
};
class B : public A {
int myInt;
public:
B():myInt(10){}
int myFct1(int val){
return myInt+val;
}
int myFct2(int val){
return myInt*2+val;
}
void Call(void){
int rez1=CallMyFct(&myFct1);
if (rez1!=20)
cout << "You are wrong" << endl;
int rez2=CallMyFct(&myFct2);
if (rez2!=30)
cout << "You are wrong" << endl;
}
};
Now I need to call these MyFct1, MyFct2, etc. from the base class, but I can not use virtual functions. So it is sorta like inversion of inheritance. I dont know if thats even possible. Do you think mem_fun or any other adapter function would work here.
I actually need to figure out what would be that PtrToFCT and how the would I pass myFct1 in the CallMyFCT.
Thanks
You have to define the functions to be called as
static, and provide additional parameter to pass to them to the object instance (instead ofthisthat they would be getting if called as regular member functions).