-
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?
-
I fixed it. But now its faulting when I try to push a second item.
-
I think you're going to have to post a bit more code.
A typical relational overload look like this...
Code:
bool Class::operator>(Class Obj)
{
if ( some test on Obj )
{
return true;
}
else
{
return false;
}
}
-
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