[英]Member's function pointer error
我有一个实现如下的类。 在构造函数中,出现编译错误。 你们能告诉我为什么吗?
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
}
};
g++
错误消息提供了更多信息:
bar.cc: In constructor 'A::A()':
bar.cc:15:11: error: must use '.*' or '->*' to call pointer-to-member function in 'h (...)', e.g. '(... ->* h) (...)'
实际上,如果您将调用更改为(this->*h)();
,它将通过编译器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.