【发布时间】:2012-11-30 14:39:56
【问题描述】:
我正在尝试使用std::bind 将this 绑定到QtConcurrent::blockingMapped 中使用的方法
标题:
class TuringMachine
{
private:
TRTable table;
std::set<ConfigNode*> currentConfigs;
//function object
std::function<std::set<ConfigNode*>( const TuringMachine*, ConfigNode*)> step_f;
//method it will hold
std::set<ConfigNode *> step(TuringMachine* this_m ,ConfigNode *parent);
std::set<ConfigNode*>& makeStep();
}
来源:
TuringMachine::TuringMachine(/**/)
{
step_f = std::bind(&TuringMachine::step, this, std::placeholders::_1);
}
std::set<ConfigNode*> &TuringMachine::makeStep(){
auto configSet = QtConcurrent::blockingMapped<QLinkedList<std::set<ConfigNode*>>>(currentConfigs, step_f);//concurrent execution!
/**/
return currentConfigs;
}
std::set<ConfigNode*> TuringMachine::step(TuringMachine *this_m, ConfigNode * parent){ //the actual step
/**/
}
所以我在这里做的是在currentConfigs 中的每个ConfigNode 上与blockingMapped 同时运行步骤。我使用std::bind 将this 绑定到step,所以它只需要一个参数,如blockingMapped 的文档中所示。
我来了
error: no match for call to '(std::_Bind<std::_Mem_fn<std::set<ConfigNode*> (TuringMachine::*)(TuringMachine*, ConfigNode*)>(TuringMachine*, std::_Placeholder<1>)>) (const TuringMachine*, ConfigNode*)'
.../Qt/474/gcc/include/QtCore/qtconcurrentmapkernel.h:121: error: no match for call to '(std::function<std::set<ConfigNode*>(const TuringMachine*, ConfigNode*)>) (ConfigNode* const&)'
.../Qt/474/gcc/include/QtCore/qtconcurrentmapkernel.h:136: error: no match for call to '(std::function<std::set<ConfigNode*>(const TuringMachine*, ConfigNode*)>) (ConfigNode* const&)'
还有note: 2 arguments expected, 1 provided
我哪里做错了?
编辑
更正的工作版本(供将来“参考”):
标题:
//function object
std::function<std::set<ConfigNode*>( ConfigNode*)> step_f;
//method it will hold
std::set<ConfigNode *> step(ConfigNode *parent);
来源:
TuringMachine::TuringMachine(/**/)
{
step_f = std::bind(&TuringMachine::step, this, std::placeholders::_1);
}
【问题讨论】:
标签: c++ c++11 qtconcurrent stdbind