Results 1 to 5 of 5

Thread: operator<

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default operator<

    how do I write that for a class X?
    I'm gonna use qSort.
    Qt Code:
    1. bool X::operator<(const X& a)
    2. {
    3. return number < a.number;}
    To copy to clipboard, switch view to plain text mode 
    don't work.

    /usr/include/qt4/QtCore/qalgorithms.h:118: error: passing `const X' as
    `this' argument of `bool X:perator<(const X&)' discards
    qualifiers
    Last edited by Morea; 10th May 2006 at 00:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: operator<

    Try:

    Qt Code:
    1. bool X::operator<(const X& a) const {
    2. return number < a.number;
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: operator<

    Super!
    That brings me to the somewhat related non-C++ question, How do you search google for the exact text
    Qt Code:
    1. operator<
    To copy to clipboard, switch view to plain text mode 

    it always ignores the < at the end.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: operator<

    Try with quotes -- "operator<"

  5. #5
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: operator<

    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.

Similar Threads

  1. How to implement operator<() for QMap
    By learning_qt in forum Qt Programming
    Replies: 6
    Last Post: 9th January 2009, 10:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.