🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #774

Re: Bogus error in type conversion (gcc-2.7.0) ??

#774
From: Eyretel Ltd.
Date: Wed, 27 Sep 1995 23:16
45 lines
2294 bytes
In article <9509251126.AA04531@voyager.cs.uni-sb.de>, neis@cs.uni-sb.de (Stefan Neis) says:
>
>        Hi there,
>
>Using g++-2.7.0 (which normally just works great...) I got a strange error
>message today:
>module_div2.C: In function `int main()':
>module_div2.C:26: call of overloaded method `operator <<(order)' is ambiguous
>alg_number.h:418: candidates are: operator <<(ostream &, const module &)
>alg_number.h:174:                 operator <<(ostream &, order &)
>
>I defined classes "order" and "module" and there is a cast - operator which
>makes modules out of orders. 
>
>Do I just not sufficiently understand the details of C++? In my opinion
>the compiler should always be able to recognize, that it should use
>operator <<(ostream &, order &)  to output an order, even if there is a
>cast from order to module, the "cast" from order to order & should be 
>prefered, shouldn't it?
>
>        Cheers,
>                Stefan
>
>P.S.: I know, I didn't supply any code, but to decide, whether this is an
>        bogus error or not, the information should be sufficient...

The compiler's confusion is justified; since it can convert an order to a
module, there is no way of telling which << it should use.

If my understanding of the error message is correct, the compiler is doing
a conversion from order to order& anyway, since there is no operator
<<(ostream &, order)

If you can't see the difference, re-read!  One's a reference, the other isn't.
Try a cast of your order object to order&, i.e instead of

cout << TheOrder  (which is confusing the compiler)

try

cout << (order&)TheOrder  (which should be specific)

The compiler does get extremely pedantic at times!  This should work; I
haven't tried it but if it fails the only other thing you can do is remove
one of the ambiguities.
Technical Details
Message-ID: <44clvv$nlc@roadrunner.atlas.co.uk>
Path: arc1-ca.pugleaf.net!atlas.co.uk!usenet
References: <9509251126.AA04531@voyager.cs.uni-sb.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!atlas.co.uk!usenet
From: eyretel@fastnet.co.uk (Eyretel Ltd.)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: Bogus error in type conversion (gcc-2.7.0) ??
Date: 27 Sep 1995 23:16:15 GMT
Organization: Eyretel Ltd.
Message-ID: <44clvv$nlc@roadrunner.atlas.co.uk>
References: <9509251126.AA04531@voyager.cs.uni-sb.de>
Reply-To: dave.spencer@castle.seuk.com
NNTP-Posting-Host: line169.atlas.co.uk
X-Newsreader: WinVN 0.92.6+