Boost bind

S

STL-BOOST

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));
 
B

Barry

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top