🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Ambiguity when overloading operators

#3996
From: Steve Clamage
Date: Fri, 12 Apr 1996 07:33
32 lines
1659 bytes
In article 1@CompuServe.COM, Martin Aupperle <100754.2730@CompuServe.COM> write
s:

>  struct  X {
>    X( int );
>    operator const char* () const;
>    };

>  X& operator + ( const X&, const X& );

>I cannot say 

>  X x1( 5 );
>  X x2 = x1+3;  // ambiguous

>Borland BC4.5 says that x1+3 is ambiguous. I know that it can
>1. convert 3 to an X and call operator + ( const X&, constX& )
>2. convert x1 to a const char* and do pointer arithmetics. 

Yes. Each choice involves exactly one user-defined conversion,
and no user-defined conversion is preferred over any other.

The compiler is correct.

---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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: <4kkam3$dg8@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <960411233436_100754.2730_GHV68-1@CompuServe.COM>

Show Full Headers
Complete Article Headers
From: clamage@Eng.Sun.COM (Steve Clamage)
Message-ID: <4kkam3$dg8@engnews1.Eng.Sun.COM>
X-Original-Date: 12 Apr 1996 01:12:35 GMT
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 12 Apr 96 07:33:34 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Ambiguity when overloading operators
Organization: Sun Microsystems Inc.
References: <960411233436_100754.2730_GHV68-1@CompuServe.COM>
Reply-To: clamage@Eng.Sun.COM
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMW4ODuEDnX0m9pzZAQELVwF+IhLm/RdkxpBRCKZbi/G2nsAYHl2GuO+w
 F9hVzl2nOVmZ/HHYWkezoV2E8DYc4B1U
 =mF1V