Boost bind

Discussion in 'C++' started by STL-BOOST, Mar 5, 2008.

  1. STL-BOOST

    STL-BOOST Guest

    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));
     
    STL-BOOST, Mar 5, 2008
    #1
    1. Advertising

  2. STL-BOOST

    Barry Guest

    On 3ÔÂ5ÈÕ, ÉÏÎç8ʱ42·Ö, STL-BOOST <> 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
     
    Barry, Mar 5, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Latter
    Replies:
    2
    Views:
    2,908
    Julie
    May 17, 2004
  2. Toby Bradshaw
    Replies:
    6
    Views:
    1,754
    Kai-Uwe Bux
    Jun 2, 2006
  3. Replies:
    0
    Views:
    591
  4. Christopher
    Replies:
    1
    Views:
    812
    Yakov Gerlovin
    Oct 5, 2011
  5. Mark
    Replies:
    1
    Views:
    434
    Jeff Flinn
    Nov 25, 2012
Loading...

Share This Page