1

I tried to use boost::bind inside a class method, which in turn calls another class method with reference parameter:

void some_method() {   
     for_each( con.begin(), con.end(), boost::bind( &comb_str::dfs, this, _1 ) );
}

void dfs( string& str ) {
... 
}

With this syntax, I got it compiled using VC++ 2010, but it passed string as a copy instead of reference. Then I tried to add boost_ref( _1 ) and I got compiler error said:

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 

Update
It actually worked without the need of boost::ref. I really apologize for being careless. Thanks for all your time reading.

Any idea?

David Nehme
  • 21,379
  • 8
  • 78
  • 117
roxrook
  • 13,511
  • 40
  • 107
  • 156
  • I recall that, in some cases, you have to specify the template arguments to `boost::bind` explicitly. Does that help? – Thomas Jan 21 '11 at 21:03
  • @Thomas: Thanks for your reply. BoostBind have 77 overloads, I'm really confused what arguments should I supply? – roxrook Jan 21 '11 at 21:19
  • So you've tried modifying str inside `dfs` and the changes did not propagate to `con`'s content? – Eugen Constantin Dinca Jan 21 '11 at 21:23
  • @Eugen Constantin Dinca: Thanks! Sorry all. It does apply reference. I don't need to explicitly add boost::ref. – roxrook Jan 21 '11 at 21:24
  • Was asking because I had no problem using this `for_each( con.begin(), con.end(), boost::bind( &comb_str::dfs, this, _1 ) );` to modify the contents of `con` inside this `void dfs( string& str )`. – Eugen Constantin Dinca Jan 21 '11 at 21:29

0 Answers0