🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Alexander Krotoff Tue, 05 Mar 1996 17:45
Inialization and user-defined conversion
#3589
Author: Alexander Krotoff
Date: Tue, 05 Mar 1996 17:45
47 lines
1819 bytes
Hello c++ gurus,

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

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 ? 

Thank you in advance,

--
Alexander N. Krotoff		krotoff@such.srcc.msu.su
Research Computer Center	tel: +7(095)939-2638
Moscow State University		fax: +7(095)939-4430
---
[ 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 
]
Re: Inialization and user-defined conversion
#3603
Author: 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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads