我尝试boost::bind
在一个类方法中使用,它又调用另一个带有引用参数的类方法:
void some_method() {
for_each( con.begin(), con.end(), boost::bind( &comb_str::dfs, this, _1 ) );
}
void dfs( string& str ) {
...
}
使用这种语法,我使用 VC++ 2010 编译它,但它string
作为副本而不是引用传递。然后我尝试添加boost_ref( _1 )
,我得到编译器错误说:
Error 1 error C2664: 'R boost::_mfi::mf1<R,T,A1>::operator ()<comb_str>(const U &,A1) const' : cannot convert parameter 2 from 'boost::arg<I>' to 'std::basic_string<_Elem,_Traits,_Ax> ' c:\program files\boost\boost_1_44\boost\bind\bind.hpp 313 1
更新
它实际上不需要 boost::ref 就可以工作。我真的为自己的粗心道歉。感谢您花时间阅读。
任何想法?