PDA

View Full Version : operator<



Morea
10th May 2006, 01:18
how do I write that for a class X?
I'm gonna use qSort.

bool X::operator<(const X& a)
{
return number < a.number;}
don't work.

/usr/include/qt4/QtCore/qalgorithms.h:118: error: passing `const X' as
`this' argument of `bool X::operator<(const X&)' discards
qualifiers

wysota
10th May 2006, 09:01
Try:


bool X::operator<(const X& a) const {
return number < a.number;
}

Morea
10th May 2006, 09:38
Super!
That brings me to the somewhat related non-C++ question, How do you search google for the exact text

operator<

it always ignores the < at the end.

wysota
10th May 2006, 12:32
Try with quotes -- "operator<"

Morea
10th May 2006, 13:02
But then the first results doesn't contain the string operator< and that is to me a proof of that operator< with quotes is not really working.