Topic: return type of overloaded comparasion operators


Author: "Yosi" <natask@hotmail.com>
Date: 1999/06/06
Raw View
Hi,

When overloading a comparasion operator (such as == !=  <  >  <=  >= )
what should be the return type? should it be 'int' or 'bool'?

Sincerely,
Yosi
natask@hotmail.com

(I will be more than grateful if you can post a copy of your reply
to my mailbox as well)



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1999/06/07
Raw View
In article <7jbnq1$3hn$1@lnews.actcom.co.il>, natask@hotmail.com
says...
>
> Hi,
>
> When overloading a comparasion operator (such as == !=  <  >  <=  >= )
> what should be the return type? should it be 'int' or 'bool'?

The standard allows you to return any type you want.  The obvious
choice is to return a bool unless you have to deal with compilers that
don't support bool yet.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: nimel@my-deja.com
Date: 1999/06/07
Raw View
In article <7jbnq1$3hn$1@lnews.actcom.co.il>,
  "Yosi" <natask@hotmail.com> wrote:

> When overloading a comparasion operator (such as == !=  <  >  <=  >= )
> what should be the return type? should it be 'int' or 'bool'?

It depends on what you mean by "should".
The standard does not mandate any return type. It can be anything,
including complex types as std::string or whatever.

In practice you probably want something that is convertable to
bool, since otherwise you cannot use that operator together with
the standard algorithm.

And from a logical point of view they should of course return a
bool.

/Niklas Mellin



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]