gpt4 book ai didi

C++ 从服务器注册回调

转载 作者:行者123 更新时间:2023-11-28 03:17:38 25 4
gpt4 key购买 nike

我的回调原型(prototype)为:

typedef void (*update)(int id,...);
typedef void (*destroy)(int id,...);
typedef void (*create)(int id, update* _update, destroy* _destroy);

然后创建回调函数:

void updateCB(int id,...){/*Add id to collection*/}
void destroyCB(int id,...){/*Remove id from collection*/}
void createCB(int id,update* _update, destroy* _destroy)
{
//Register Callbacks
*_update = updateCB;
*_destroy = destroyCB;
}

当我注册回调时编译器给我错误:

error: cannot convert 'ClassName::updateCB' from type 'void (ClassName::)(int,...)' to type 'update {aka void (*)(int..)}'

我如何才能有效注册回调?

最佳答案

您正在尝试使用成员函数,这在这种情况下是不可能的。发生这种情况是因为每个成员函数(如果它不是静态的)都带有指向类实例的隐藏指针this。您需要使用全局函数或静态成员函数。

关于C++ 从服务器注册回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16356762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com