🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3603

Re: Inialization and user-defined conversion

#3603
From: James Kanze US/ESC 60/3/141 #407...
Date: Wed, 06 Mar 1996 18:06
57 lines
2654 bytes
In article <199603051249.PAA00513@boy.nmd.msu.ru> Alexander Krotoff
<krotoff@boy.nmd.msu.ru> writes:

|> I have a confusion with initialization of class objects.
|> Example:

|> class C {
|>  public:
|> 	C(int i);
|> };

|> class D {
|>  public:
|> 	D(C c);
|> };

|> D d = 1;

|> void f()
|> {
|> 	D d = 1;
|> }

|> I assume, that both initializations are wrong, since they require sequence
|> of two user-defined conversions. But some compilers disaggre ;-)

Correct.  This is a difference in the initialization formats: if you
had written `D d( 1 )', they would be legal.  Apparently, some
compilers are not making the distinction.  (The compiler is allowed to
optimize out the temporary and the call to the copy constructor, but
this is just an optimization, and is not allowed to affect the
legality of the program.)

|> Boralnd c++ 4.0:	cannot convert "int" to "D"
|> g++ 2.7.2:		no matching funcion for call to "D::D(int)"
|> MS VC 4.0:		no errors
|> Watcom 10.0:		no errors

|> As seems to me only Borland gives adequate diagnostics.

|> Who is right ? 

Borland and g++.  While I find the g++ diagnostics acceptable, it's
true that the Borland one is clearer, particularly for a neophyte.

--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
                -- A la recherche d'une activité dans une region francophone
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <9603061803.AA11656@lts.sel.alcatel.de>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <199603051249.PAA00513@boy.nmd.msu.ru>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
Newsgroups: comp.std.c++
Subject: Re: Inialization and user-defined conversion
Date: 06 Mar 1996 10:06:23 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <9603061803.AA11656@lts.sel.alcatel.de>
References: <199603051249.PAA00513@boy.nmd.msu.ru>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Wed, 6 Mar 96 19:03:55 +0100
In-Reply-To: Alexander Krotoff's message of 05 Mar 1996 09:45:02 PST
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMT3UK0y4NqrwXLNJAQGOlAIAztAZ/+9pSaMDt8M7MhtFWNhs+NVKimSR
 z+YLyiWP4WFxWzq5A+sjyqRfWTpn9vjx1HHSf3ZJLelNf+vY7aVDjg==
 =d/Rd
Originator: austern@isolde.mti.sgi.com