参考:
1.http://www.tianya.cn/publicforum/content/it/1/256804.shtml
2.http://bbs.bccn.net/thread-47699-1-1.html
类中的成员函数指针的声明与使用方法,注:编译通过,但不知运行结果。
摘录:
构造一个指向成员的指针需要显式使用地址运算符&和限定名。
从类的外部访问该类的成员需要范围解析运算符 (::) 和地址运算符&。生成下面的示例 C2475:
// C2475.cpp
#include <stdio.h>
struct A {
void f() {
printf("test");
}
void g();
};
void A::g() {
void (A::*p1)() = f; // ok in -Ze; error in -Za (C2475)
void (A::*p5)() = this->f; // C2475
// the following line shows how to call a function from outside the class
// void (A::*p4)() = &A::f;
}
int main() {
A *ap = new A;
A a;
void (A::*p5)() = a.f; // C2475
// the following line shows how to call a function from outside the class
void (A::*p4)() = &A::f;
// the following line shows how to call a member function
(ap->*p4)();
return 0;
}