Thread: Overloading the < Operator

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You need to make the getreq function const by adding the keyword const after the parameter list parentheses, e.g.
    Code:
    int getreq() const;
    That tells the compiler that the function won't change the state of the object, which is what the compiler needs to know before it allows you to call it from a const object (or a reference to a const object).

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Make sure your operator < is also declared as a static or friend function, since you're using the two-parameter form (which btw is the preferred method).
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  2. Overloading == and < operator
    By cannsyl in forum C++ Programming
    Replies: 3
    Last Post: 11-23-2008, 10:21 PM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM