When overloading the comparison operators, do they return an int or a bool data type?
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?...
When overloading the comparison operators, do they return an int or a bool data type?
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-01-2003 at 11:48 PM.
true, but most of the time:
>
<
>=
<=
etc.
would return bool.
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