I’ve a class implemented as below. In the constructor, I get a compilation error. Would you guys please tell my why?
class A{
public:
typedef void (A::*HANDLER)();
void test1(){
printf("This is test 1");
}
void test2(){
printf("This is test 2");
}
A(){
HANDLER h= &A::test1;
h(); // an error spawn here with the description: term does not evaluate to a function taking 0 arguments
}
};
You should use, pointer to member operator
->*in this way:Online Demo of your code sample.