希望想理解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 = ⁡ 22 (paf->*pFunc)(11); 23 24 return 0; 25 }