c++回调函数
函数指针
//函数
bool lengthCompare(const string&, const string&);
//pf为指针,指向一个函数,函数的类型为:bool (const string&, const string&)
bool (*pf)(const string&, const string&);
//函数,返回值为:bool*。*pf两端的括号必不可少。如果不写这对括号,则pf是一个返回值为bool指针的函数
bool *pf(const string&, const string&);
//函数
bool lengthCompare(const string&, const string&);
//pf为指针,指向一个函数,函数的类型为:bool (const string&, const string&)
bool (*pf)(const string&, const string&);
//函数指针 指向 lengthCompare
pf = lengthCompare;
//等价 取地址符&是可选的
pf = &lengthCompare;
在C/C++中,typedef的作用是为复杂类型定义一个易读的别名。针对你提供的代码:
typedef int (*CompareFunction)(const byte*, const byte*);
CompareFunction cmp = my_compare_function;
CompareFunction相当于int (*CompareFunction)(const byte*, const byte*);