• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: strange looking ambiguity with type cast
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strange looking ambiguity with type cast


  • Subject: Re: strange looking ambiguity with type cast
  • From: GoochRules! <email@hidden>
  • Date: Wed, 11 Feb 2004 14:02:39 -0700

On Feb 11, 2004, at 1:19 PM, jean-frangois gauthier wrote:

(please point me to another list if this is not the right place to
discuss this) it seems to me the following should just compile:

class a
{
public :
	a (int) ;
} ;

class b
{
public :
	operator a (void) ;
	operator int (void) ;
} ;

int main (int, char ** const)
{
	b _b ;
	(a) _b ;
}

but gcc complains:
error: call of overloaded `a(b&)' is ambiguous
error: candidates are: a::a(const a&)
error:                 a::a(int)

why? this compiles fine with cwpro and msdev. it compiles if i replace
(a) _b with _b. operator a ().


To me it looks like gcc is finding two possible user-defined conversion operators to create an 'a' from a 'b' because there's a default copy constructor for a (the first candidate), and the overloaded constructor you provided (the second candidate).


This situation is rather interesting because the C++ standard dictates that only one user-defined implicit conversion can be done in an expression. To translate (a) _b; into a::a(_b.operator a()) or a::a(_b.operator int()) seems to only need one implicit conversion, so the code should not work on a standards-conforming compiler.

I bet the code will compile if you remove either the overloaded constructor a::a(int), or either operator in b. You could also try making a::a(const a&) private.

jean-frangois
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: strange looking ambiguity with type cast
      • From: jean-françois gauthier <email@hidden>
References: 
 >strange looking ambiguity with type cast (From: jean-françois gauthier <email@hidden>)

  • Prev by Date: Frameworks/multiply-defined symbols
  • Next by Date: Re: strange looking ambiguity with type cast
  • Previous by thread: strange looking ambiguity with type cast
  • Next by thread: Re: strange looking ambiguity with type cast
  • Index(es):
    • Date
    • Thread