1.回调函数的本质就是函数调用函数指针作为形参传到要处理的函数内部作处理。
// 回调函数指针
typedef void(*fun)(QString id, QString str);
//存放调用函数类型和函数指针的map
static std::map<QString, fun> callbackfun_map;
// 要被回调函数
void test(QString id,QString str)
{
cout << id << ":" << str;
// ...
}
// XXX.cpp类 初始化
void initfun()
{
callbackfun_map.insert({"test",test});
}
//要调用的地方
// ...
auto testfun = callbackfun_map.find("test");
testfun("test","1");