C++指向类成员函数的指针

来源:互联网 发布:淘宝新店怎么升级 编辑:程序博客网 时间:2024/06/05 04:55
 1 #include <iostream>
 2 
 3 using std::cout;
 4 using std::cin;
 5 using std::cerr;
 6 using std::endl;
 7 
 8 class Obj
 9 {
10 public:
11     double func(int p1, int p2)
12     {
13         return (p1+p2);
14     }
15 };
16 
17 typedef double (Obj::*  /*AS*/FcnPtrType/*(end of name)*/  )( intint );
18 
19 int main(int argc, char** argv)
20 {
21     double (Obj::* fontPtr)(intint= &Obj::func;
22     Obj obj;
23     cout << (obj.*fontPtr)(37<< endl;
24     
25     system("pause");
26     return 0;
27 }
28 
0 0
原创粉丝点击