【发布时间】:2016-03-23 15:45:50
【问题描述】:
我有一个 shared_ptr 的向量,我想结合 boost shared_ptr 并绑定在一起。
我的问题与this 非常相似,只是我想调用“&Element::Fn”而不是“&MyClass::ReferenceFn”。
这是一段类似的代码:
typedef boost::shared_ptr< Vertex > vertex_ptr;
std::set<vertex_ptr> vertices;
void B::convert()
{
...
if( std::find_if(boost::make_indirect_iterator(vertices.begin()),
boost::make_indirect_iterator(vertices.end() ), boost::bind( &Vertex::id, boost::ref(*this), _1 ) == (*it)->id() ) == vertices.end() )
}
这是错误:
no matching function for call to ‘bind(<unresolved overloaded function type>, const boost::reference_wrapper<B>, boost::arg<1>&)’
注意:我仅限于使用 C++03。
【问题讨论】:
-
你得到什么错误?
-
@PiotrSkotnicki,错误是它把(this关键字)作为B类的this指针
-
然后你想要
boost::bind(&Vertex::id, _1) == (*it)->id()),或者boost::bind(static_cast<int(Vertex::*)()>(&Vertex::id), _1) == (*it)->id())(其中int是id的返回类型) -
非常感谢,如果您提供评论作为答案,我会选择它作为最佳解决方案。另外请您解释一下“(Vertex::*) 中的星号是什么意思?
标签: c++ boost shared-ptr boost-bind