mem_fun error

Discussion in 'C++' started by joseph cook, Mar 7, 2007.

  1. joseph  cook

    joseph cook Guest

    I am getting a compile error on any compiler I try, so I know I have
    an error here. Can anyone see it?

    //includes

    class Foo
    {
    public:
    Foo(int a){m_hi = a;}
    int hi(){return m_hi;}

    int m_hi;
    };

    int main()
    {
    std::vector<Foo *> data;
    data.push_back(new Foo(3));

    max_element(data.begin(),
    data.end(),
    std::mem_fun(&Foo::hi));

    }

    gives a compile error:
    in gcc: stl_algo.h:4565: error: no match for call to
    '(std::mem_fun_t<int, Foo>) (Foo*&,Foo*&)'
    stl_function.h:600: note: candidates are: _Ret
    std::mem_fun_t<_Ret,_Tp>::eek:perator()(_Tp*) const [with _Ret = int,
    _Tp = Foo]

    help!

    }
    joseph cook, Mar 7, 2007
    #1
    1. Advertising

  2. joseph cook wrote:
    > I am getting a compile error on any compiler I try, so I know I have
    > an error here. Can anyone see it?
    >
    > //includes
    >
    > class Foo
    > {
    > public:
    > Foo(int a){m_hi = a;}
    > int hi(){return m_hi;}


    This is not a proper comparison function.

    >
    > int m_hi;
    > };
    >
    > int main()
    > {
    > std::vector<Foo *> data;
    > data.push_back(new Foo(3));
    >
    > max_element(data.begin(),
    > data.end(),
    > std::mem_fun(&Foo::hi));


    The third argument needs to be a comparison function with a very
    specific signature. Think how your 'hi' should be used with TWO
    arguments of type Foo*.

    >
    > }
    >
    > gives a compile error:
    > in gcc: stl_algo.h:4565: error: no match for call to
    > '(std::mem_fun_t<int, Foo>) (Foo*&,Foo*&)'
    > stl_function.h:600: note: candidates are: _Ret
    > std::mem_fun_t<_Ret,_Tp>::eek:perator()(_Tp*) const [with _Ret = int,
    > _Tp = Foo]
    >
    > help!
    >
    > }


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Mar 7, 2007
    #2
    1. Advertising

  3. joseph  cook

    joseph cook Guest


    >
    > > int main()
    > > {
    > > std::vector<Foo *> data;
    > > data.push_back(new Foo(3));

    >
    > > max_element(data.begin(),
    > > data.end(),
    > > std::mem_fun(&Foo::hi));

    >
    > The third argument needs to be a comparison function with a very
    > specific signature. Think how your 'hi' should be used with TWO
    > arguments of type Foo*.


    Of course; thank you.
    joseph cook, Mar 7, 2007
    #3
    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. k0tic
    Replies:
    1
    Views:
    573
    Alf P. Steinbach
    Sep 4, 2003
  2. Maitre Bart

    STL custom mem_fun

    Maitre Bart, Feb 10, 2004, in forum: C++
    Replies:
    2
    Views:
    582
    Maitre Bart
    Feb 11, 2004
  3. Old Wolf

    mem_fun with template function

    Old Wolf, Aug 16, 2004, in forum: C++
    Replies:
    5
    Views:
    686
    Daniel T.
    Aug 17, 2004
  4. Robbie Hatley

    Problem using mem_fun.

    Robbie Hatley, Oct 24, 2004, in forum: C++
    Replies:
    2
    Views:
    1,195
    Robbie Hatley
    Oct 25, 2004
  5. joseph  cook

    mem_fun error

    joseph cook, Mar 7, 2007, in forum: C++
    Replies:
    4
    Views:
    370
    Sarath
    Mar 8, 2007
Loading...

Share This Page