[C++基础]028_获取类成员函数的指针

 1 #include <iostream>
 2 using namespace std;
 3 
 4 class A 
 5 {
 6 public:
 7     static void staticmember(){cout<<"static"<<endl;}
 8     void nonstatic(){cout<<"nonstatic"<<endl;}
 9     virtual void virtualmember(){cout<<"virtual"<<endl;}
10 };
11 
12 int main()
13 {
14     A a;
15     void (*ptrstatic)() = &A::staticmember;
16     void (A::*ptrnonstatic)() = &A::nonstatic;
17     void (A::*ptrvirtual)() = &A::virtualmember;
18 
19     ptrstatic();
20     (a.*ptrnonstatic)();
21     (a.*ptrvirtual)();
22 
23     system("pause");
24     return 0;
25 }
posted @ 2012-10-16 10:22  邵贤军  阅读(1012)  评论(1编辑  收藏  举报