[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: stupid C++ question / operator overloading / Qt
From:       Bo Thorsen <bo () sonofthor ! dk>
Date:       2001-02-27 19:21:34
[Download RAW message or body]

On Tue, 27 Feb 2001, Dirk Mueller wrote:
> I noticed that Qt uses "int operator==(foo, bar)" while my C++ book
> (Stroustrup) says something about "bool operator==(foo, bar)". Is it just
> sad that gcc doesn`t warn about this, or is it really useful/legal
> to do something like that ?
>
> Are there compilers out there needing this specific return type ?
>
> I'm just wondering.. it seems to have a dramatic effect on code generation
> for g++/gcc when changing the return type to "bool". strange world.

GCC can't complain since operator== is just a function being defined. It
is purely an agreement that this performs equality tests and that it
usually returns a bool. And it works without problems because ints can be
used in bool tests without casts.

Blame the horrible design of operator overloading in c++ for the confusion
you just saw.

Bo.

-- 

     Bo Thorsen                 |   Lahnsgade 31, st.
     Free software developer    |   5000 Odense C
     SuSE Labs                  |   Denmark

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic