Thread: overloading >

  1. #1

    overloading >

    So I have a class with a > operator overloaded method. Its to use it with the priority_queue.
    if I do:
    bool operator>( const X& x0 )
    { return ( y > x0.y ); }
    it gives me a compiling error, something like, no operator which takes a left hand object.
    If I do
    bool operator>( const X& x0, const X& x1 )
    { return ( x0.y > x1.y ); }
    It says operator> has too many parameters.
    Any suggestions?

  2. #2
    I fixed it. But now its faulting when I try to push a second item.

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    I think you're going to have to post a bit more code.

    A typical relational overload look like this...

    bool Class::operator>(Class Obj)
        if ( some test on Obj )
            return true;
            return false;
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    have you declared the second one as a friend function? then it takes 2 arguments, otherwise it'll need to be a member function where you can use the this pointer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading -> (and ->*)
    By AverageSoftware in forum C++ Programming
    Replies: 4
    Last Post: 06-10-2007, 12:35 PM
  2. C++ Overloading < > == for use with char * or string
    By neolyn in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2004, 03:37 PM
  3. Overloading -> operator
    By Hunter2 in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2004, 03:08 PM
  4. Opinion on Overloading < and > For My Number Class
    By golfinguy4 in forum C++ Programming
    Replies: 5
    Last Post: 07-01-2003, 05:33 PM
  5. Overloading < or > operators
    By mouse163 in forum C++ Programming
    Replies: 3
    Last Post: 03-30-2003, 08:32 PM