用法:
类:Test
Test.h
class Test
{
public:
Test();
void TestFunPtr();
~Test();
protected:
// 注意此处声明使用Test::*fun_ptr
void Fun(int (Test::*fun_ptr)(int, int));
int Handler(int a, int b);
};
Test.cpp
Test::Test()
{
}
void Test::TestFunPtr()
{
/// 注意此处调用
int (Test::*Handler_ptr)(int, int) = &Test::Handler;
Fun(Handler_ptr);
}
void Test::Fun(int (Test::*fun_ptr)(int, int))
{
// 注意this->*fun_ptr 不知道为什么要这么指向,估计和c++编译相关
(this->*fun_ptr)(3, 4);
}
int Test::Handler(int a, int b)
{
printf("%d, %d\n",a, b);
return 1;
}
Test::~Test()
{
}