Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Boost bind

Reply
Thread Tools

Boost bind

 
 
STL-BOOST
Guest
Posts: n/a
 
      03-05-2008
Hi,all. I hanve a class T, and T has a member fuanction func(int a,
int b), In vector<shared_ptr<T>>, how can I use
for_each, this does not compiled:
for_each(v.begin(), v.end(), bind(&T::func, _1)(a, b));
 
Reply With Quote
 
 
 
 
Barry
Guest
Posts: n/a
 
      03-05-2008
On 3月5日, 上午8时42分, STL-BOOST <(E-Mail Removed)> wrote:
> Hi,all. I hanve a class T, and T has a member fuanction func(int a,
> int b), In vector<shared_ptr<T>>, how can I use
> for_each, this does not compiled:
> for_each(v.begin(), v.end(), bind(&T::func, _1)(a, b));


"boost::bind(x, y, z)" is to produce a functor.
while your code "bind(&T::func, _1)(a, b)",
the syntax means that you already invoke the functor,
and return what "T::func" returns.

so I think you should write "bind(&T::func, _1, a, b)" instead.

HTH

--
Best Regards
Barry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
boost::bind with boost::fusion::for_each Mark C++ 1 11-25-2012 06:17 PM
pass a boost::function as an argument to boost::bind Christopher C++ 1 10-05-2011 11:35 AM
confused by boost::bind & boost::lambda::bind XHengDF@gmail.com C++ 0 05-29-2007 04:37 AM
Problems mixing boost::lambda::bind and boost::shared_ptr.. Toby Bradshaw C++ 6 06-02-2006 04:12 PM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM



Advertisments