functors with reference parameters

Discussion in 'C++' started by red floyd, Nov 13, 2003.

  1. red floyd

    red floyd Guest

    Disclaimer: VS.NET 2003 (haven't checked any other compiler).

    I'm writing functors for my classes.
    Because the objects in my containers are large, I'm making my functors take const T& parameters.

    If I try std::bind2nd() with one of these classes, I get an error about a reference to a reference.

    What's the proper way to declare functors taking const T& parameters so that they play nicely with adapters?

    Would it be something like the following? What should I use as the params to unary_function? I can't quite
    figure it out from Josuttis.

    class myClass
    {
    // internals redacted
    };

    class myFunctor : public std::unary_function<myClass, void>
    {
    public:
    void operator()(const myClass& elem)
    {
    // do something with elem here
    }
    };


    TIA
     
    red floyd, Nov 13, 2003
    #1
    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. Paul MG
    Replies:
    2
    Views:
    394
    Dhruv
    Jul 3, 2003
  2. Rob Williscroft

    Re: Need help with generic functors....

    Rob Williscroft, Aug 17, 2003, in forum: C++
    Replies:
    3
    Views:
    347
    Gordon Scott
    Aug 18, 2003
  3. nsgi_2004

    functors

    nsgi_2004, Aug 12, 2004, in forum: C++
    Replies:
    2
    Views:
    467
    Karl Heinz Buchegger
    Aug 12, 2004
  4. Satish
    Replies:
    1
    Views:
    790
    David Hilsee
    Sep 10, 2004
  5. Michael

    functors and stl find_if

    Michael, Feb 19, 2005, in forum: C++
    Replies:
    4
    Views:
    6,280
    SnaiL
    Feb 19, 2005
Loading...

Share This Page