C++的回调函数定义方法使用了无数次,就是记不住。。。这里再copy一次:
1 typedef int (*callback)(int param1, char* param2);
2
3 Syntax
4 typedef return_code (*function_virtual_name)(parameters list);
5
6 Example
7 class CCall;
8 typedef int (*callback)(CCall* call, int i);
9 class CCall{
10 public:
11 CCall(int i = 0)
12 : _i(i)
13 {};
14 virtual ~CCall() {}
15
16 int becall(int i) { return call(i); }
17 virtual int call(int i) = 0;
18 private:
19 int _i;
20 };
21
22 static int Func(CCall* call, int i)
23 {
24 return call->becall(i);
25 }
26