Quick question about operator overloading

This is a discussion on Quick question about operator overloading within the C++ Programming forums, part of the General Programming Boards category; When overloading the comparison operators, do they return an int or a bool data type?...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    11

    Quick question about operator overloading

    When overloading the comparison operators, do they return an int or a bool data type?

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Operator overloading means you define what the operator functions do in relation to objects of your class. When you overload the comparison operators, you can have them return the string "Hello world" if you want. It's entirely up to you. Just like any other function, you define the operator functions to do whatever you want them to do.
    Last edited by 7stud; 04-02-2003 at 12:48 AM.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    true, but most of the time:

    >
    <
    >=
    <=
    etc.

    would return bool.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    comparison operators return bool
    arithmetic operators return objects
    assignment and arithmetic assignment returns a reference to *this
    >> and << stream operators return a reference to the stream.

    Thats probably about the most general advice I can give.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21