Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Boost bind (http://www.velocityreviews.com/forums/t596087-boost-bind.html)

STL-BOOST 03-05-2008 12:42 AM

Boost bind
 
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));

Barry 03-05-2008 05:00 AM

Re: Boost bind
 
On 3月5日, 上午8时42分, STL-BOOST <wartal...@gmail.com> 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


All times are GMT. The time now is 11:47 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57