-1
我的问题是无效的转换函数指针到成员函数。 当coap_handler成员函数是静态的时候,一切都很好。 CoapClient的实例不能是静态的和全局的。我想从coap_handler()中移除静态。如何做到这一点?由于无效的转换函数指针到成员函数
class CoapClient{
...
void connect(){
mg_connect(&mgr, address.c_str(), coap_handler);
}
static void coap_handler(struct mg_connection *nc, int ev, void *p) {
...
}
};
//////签名mg_connect function
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
mg_event_handler_t callback);
//////签名mg_event_handler_t
回调函数(事件处理程序)的原型。必须由用户定义。 Mongoose调用事件处理程序,传递下面定义的事件。
typedef void (*mg_event_handler_t)(struct mg_connection *, int ev, void *);
你不能?成员函数指针需要有一个实例来调用它们。 –
连接方法在CoapClient类的构造函数中调用。 –
发布一个[MCVE],可以真实地展示您的问题。 –