🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by David C Binderman Wed, 10 Jan 1996 08:21
ambiguous or not ?
#3000
Author: David C Binderman
Date: Wed, 10 Jan 1996 08:21
87 lines
1704 bytes
Hello there,

Following on from an outbreak of compiler disagreement,

// is this ambiguous or not ?

// workaround is to use cast on lhs



#include <iostream.h>


class S
{

public:
	
	S( char ) {
		
		cerr << "S::S char\n";
	
	};
	
	S( unsigned char ) {
		
		cerr << "S::S char\n";
	
	};
};



operator == ( char, const S &)
 
{
	
	cerr << "operator ==\n";

};



class R
{

public:
	
	enum { a, b, c};
	
	operator int () {
		
		cerr << "R::operator int\n";
	
	};

};



int
main()

{
	
	R z;
	
	// if ((int) z == R::a)
	// workaround line
	if (z == R::a)
 // ambiguous ?
		;

}

my opinion is that the code is ok, and the compilers that think it is
ambiguous are wrong.

Your opinion sought

Regards
David Binderman MSc BSc    +44 1293 544 364       dcb@pncl.co.uk
      If only everything in life was as reliable as a Toyota
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: ambiguous or not ?
#3003
Author: Steve Clamage
Date: Wed, 10 Jan 1996 23:18
78 lines
2429 bytes
In article WAA27727@eiger.pncl.co.uk, dcb@pncl.co.uk (David C Binderman)
writes:

Ignoring the several errors in this sample code, the comparison is not
ambiguous. You are comparing, in effect, the types
	R == enum

There are two viable functions:
1. built-in operator==(int,int)
2. operator==(char, const S&)
(None of the other built-in comparison "functions" could be called.)

Function 1 requires a user-defined conversion on the first argument and
a promotion on the second.

Function 2 requires a user-defined conversion on both arguments (plus
extra standard conversions which don't affect the analysis).

Thus, Function 1 is preferred, and there is no ambiguity.

There would be an ambiguity in choosing Function 2, since the enum could be
converted to an S by first converting it to a char or unsigned char. But
since Function 1 is unconditionally preferred, it doesn't matter how many
potential ambiguities exist in using functions which are not preferred.

---
Steve Clamage, stephen.clamage@eng.sun.com


>Following on from an outbreak of compiler disagreement,

>// is this ambiguous or not ?

>// workaround is to use cast on lhs

>#include <iostream.h>

>class S
>{

>public:
>	S( char ) {
>		cerr << "S::S char\n";
>	};
>	
>	S( unsigned char ) {
>		cerr << "S::S char\n"
>	};
>};

>operator == ( char, const S &)
>{
>	cerr << "operator ==\n";
>};

>class R
>{
>public:
>	enum { a, b, c};
>	operator int () {
>		cerr << "R::operator int\n";
>	};
>};

>int
>main()
>{
>	R z;
>	// if ((int) z == R::a)
>	// workaround line
>	if (z == R::a)
> // ambiguous ?
>		;
>}
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
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