c++ bind 绑定类中的方法

来源:互联网 发布:一键上传淘宝软件 编辑:程序博客网 时间:2024/06/06 12:40

今天在使用find_if 与 bind 的时候,遇到了一些问题。在网上找到的例子中绑定的方法是全局的,格式是这样的:

vector<int> vec;

//略去vecotr push_back 操作......

find_if(vec.begin(),vec.end(),bind(函数,参数或placeholders));

但是我在类里面按照这种格式写的时候出现了如下错误:

错误 C2672“operator __surrogate_func”: 未找到匹配的重载函数

错误 C2893未能使函数模板“unknown-type std::_Binder<std::_Unforced,bool (__thiscall pcb_pool::* )(pcb &,UINT),const std::_Ph<1> &,UINT &>::operator ()(_Unbound &&...) const”专用化

解决办法是在绑定的函数后添加一个*this ,之后再写参数与placeholders

std::find_if(pcb_table.begin(), pcb_table.end(), bind(&pcb_pool::isFindPcbId,*this , placeholders::_1, pcb_id));

原创粉丝点击