I have a class that contains two similar non-static functions, I want to assign one of them on the fly to a function pointer:
A.h:
class A{
private:
void (*funcPtr)(int);
void do_sth(int i);
void do_sth_else(int i);
}
A.cpp:
A::A(int i){
if(i == 1)
A::funcPtr = A::do_sth; // or &A::do_sth;
else
A::funcPtr = A::do_sth_else; // or &A::do_sth_else;
}
But I get such error:
error: cannot convert 'A::do_sth' from type 'void (A::)(int)' to type 'void (*)(int)'
I read multiple similar issues, But cannot apply their solutions on my problem.