🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#778
From: Stefan Neis
Date: Mon, 02 Oct 1995 16:54
50 lines
2483 bytes
Eyretel Ltd. (eyretel@fastnet.co.uk) wrote:
: 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. 
: >
: > (Stuff from my original posting deleted;
: 
: 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.

Bjarne Stroustrup states (in "The C++ programming language", p.589):
"[1] Exact match: Sequences of zero or more trivial conversions are
	better than all other sequences...."

	(Note: Conversion from "order" to "order &" is such a so
	called trivial conversion)

So in my understanding, the compiler should detect, that
	"operator <<(ostream &, order &)"
matches better, than "operator <<(ostream &, const module &) which
involves a "user defined conversion", shouldn't it?

Note, that gcc-2.6.3 does not give this error. It produces perfectly
well working code.

: 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)

Well, I still assume, that such "trivial conversions" aren't really
counted -- unless that's been changed in the ANSI-draft-standard.
 
: 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&.

Of course I tried that and it works, but I didn't understand, why this
should be necessary...


	Stefan Neis
Technical Details
Message-ID: <44p5gu$jp2@hades.rz.uni-sb.de>
Path: arc1-ca.pugleaf.net!crypt4.cs.uni-sb.de!not-for-mail
References: <9509251126.AA04531@voyager.cs.uni-sb.de> <44clvv$nlc@roadrunner.atlas.co.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!crypt4.cs.uni-sb.de!not-for-mail
From: neis@cs.uni-sb.de (Stefan Neis)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: Bogus error in type conversion (gcc-2.7.0) ??
Followup-To: gnu.g++.help,comp.lang.c++
Date: 2 Oct 1995 16:54:54 GMT
Organization: University of Saarland, Computing Center, Germany.
Message-ID: <44p5gu$jp2@hades.rz.uni-sb.de>
References: <9509251126.AA04531@voyager.cs.uni-sb.de> <44clvv$nlc@roadrunner.atlas.co.uk>
NNTP-Posting-Host: crypt4.cs.uni-sb.de
X-Newsreader: TIN [UNIX 1.3 950427BETA PL0]