希望想理解C++委托的同学,能够从代码中悟出其中的原理。有什么不太清楚的地方,欢迎留言交流。

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define debug(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
 5 
 6 class AF
 7 {
 8 public:
 9     AF() {}
10     void Func(int x){
11         cout << "AF::Func " << x << endl;
12     }
13 };
14 
15 void (AF::*pFunc)(int) = &AF::Func;
16 
17 int main(int argc, char *argv[])
18 {
19     AF af;
20     (af.*pFunc)(10);
21     AF *paf = &af;
22     (paf->*pFunc)(11);
23 
24     return 0;
25 }
成员函数指针的操作

相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2021-06-16
  • 2021-09-10
  • 2022-02-03
  • 2021-08-15
  • 2021-12-03
  • 2021-09-08
猜你喜欢
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案