🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Constructors and conversion operator

#3706
From: Roman Lechtchinsky
Date: Mon, 18 Mar 1996 08:02
73 lines
1835 bytes
Hi,

I have a question about conversion operators and constructors. Consider the 
following:

class X
{
	X( Y );
};

class Y
{
	Y();

	operator X();
};

void foo( X );

int main()
{
	Y y;
	foo1(y);
	foo1(X(y));
	foo1((X)y);
};

In all three cases my compiler says that the call is ambiguous. Is it 
correct? The DWP says:

	User-defined conversions are used implicitly only if they are 
unambiguous. [class.conv.fct]

What is meant by user-defined conversions - only conversion operators or both 
conversion operator and converting constructors?

Now the second one:

class A
{
		A(B);
};

class B
{
		operator A&();
};


void foo( A )
{}

int main()
{
	B b;

	foo( b );
	foo(A(b));
	foo((A)b);
}

Again, my compiler complains about all three calls. In fact, it complains 
even about A a = A(b). Is this correct?

Bye

Roman
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Technical Details
Message-ID: <314CD29A.3438@cs.tu-berlin.de>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Message-ID: <314CD29A.3438@cs.tu-berlin.de>
X-Original-Date: Mon, 18 Mar 1996 04:03:54 +0100
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 18 Mar 96 08:02:41 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Constructors and conversion operator
Organization: Technical University of Berlin
X-Mailer: Mozilla 2.0 (Win95; I)
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMU0YxuEDnX0m9pzZAQEGDwF9GG0npd/5JHLBtEZnio3leXumNS6zkLnX
 uZ+X1HQPJHITH8vMzj3VCcfKS6PkAXXE
 =hj4C