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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top