《一》一般函数指针用法:
《一》一般函数指针用法:
typedef char (*PTRFUN)(int);
PTRFUN pFun;
char glFun(int a){ return;}
void main()
{
pFun = glFun;
(*pFun)(2);
}
《二》成员函数指针用法:
template <typename ClassType, typename ParaType> class CC { public: /*函数指针类型模板*/ typedef ParaType (ClassType::*pClassFun)(ParaType, ParaType);
/*函数指针函数模块*/ ParaType Result(ClassType* pClassType, pClassFun fun, ParaType a, ParaType b) { return (pClassType->*fun)(a, b); } };
《三》使用函数指针做代理:
template <class TTpFuncClass>
void ttMakeFuncObject(TTpFuncClass& theFuncObject, void (TTpFuncClass::*pFunction)())
{
(theFuncObject.*pFunction)();
}
class TTFuncObject{
public:
TTFuncObject()
{
}
void add()
{
cout<< "TTFuncObject::add()" << endl;
}
};
int main(int argc, char* argv[])
{
TTFuncObject aTTFuncObject;
ttMakeFuncObject(aTTFuncObject, &TTFuncObject::add);
return 0;
}
转载于:https://www.cnblogs.com/lemonZ/p/3422281.html