1 #include <iostream>
2 using namespace std;
3
4 class myclass
5 {
6 public:
7 int add(
int a,
int b)
8 {
9 return a +
b;
10 }
11 };
12
13 void main()
14 {
15 myclass my1;
16 my1.add(
1,
3);
17 //创建一个函数指针指向一个类成员函数
18 int (myclass::*p)(
int,
int) = &
myclass::add;
19 //p(1,2);不能这样用,因为需要一个this指针
20 cout << (my1.*p)(
1,
23) <<
endl;
21
22 myclass *pmy = &
my1;
23 cout << (pmy->*p)(
1,
34) <<
endl;
24 cin.
get();
25 }
转载于:https://www.cnblogs.com/xiaochi/p/8584070.html
转载请注明原文地址: https://win8.8miu.com/read-27215.html