class EmulNet
{
public:
int ENrecv(Address *myaddr, std::function<int (void*,char*,int)> fn, struct timeval *t, int
times, void *queue);
};
class MP1Node{
public:
int recvLoop();
int enqueueWrapper(void *env, char *buff, int size);
};
int MP1Node::recvLoop() {
return emulNet->ENrecv(&(memberNode->addr), std::bind(&MP1Node::enqueueWrapper,this), NULL, 1, &(memberNode->mp1q));
}
注意-emulNet是EmulNet类的对象
以上代码无效。
No viable conversion from '__bind<int (MP1Node::*)(void *, char *, int), MP1Node *>' to 'std::function<int (void *, char *, int)>'
如果您坚持使用std::bind
,请加入
std::bind(&MP1Node::enqueueWrapper,this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
或者,使用lambda:
[this](void *env, char *buff, int size) { return enqueueWrapper(env, buff, size); }
(用上面的内容替换您的bind
通话。