[comp.lang.c++] supposedly ambiguous conversion

cok@islsun.Kodak.COM (David Cok) (10/24/90)

Consider this program, which gives compilation errors.  It is boiled out of
a larger more useful context.

class Byte;
class Int;
class Float;

class Double { 
    public:
	double v;

	Double();
	Double(const Double&);

	Double(Byte);
	Double(Int);
	Double(Float);

	friend Double operator + (Double a, Double b);
};

class Float { 
    public:
	float v;

	Float();
	Float(const Float&);

	Float(Int);
	Float(Byte);

	friend Float operator + (Float a, Float b);
};

class Int { 
    public:
	int v;

	Int();
	Int(const Int&);

	Int(Byte);

	friend Int operator + (Int a, Int b);
};

class Byte { 
    public:
	unsigned char v;

	Byte();
	Byte(const Byte&);

	friend Byte operator + (Byte a, Byte b);
};


main()
{
	Byte 	b;
	Int	i;

	b+i;
}



Sun C++ 2.0 on a SparcStation 1 says the following:

CC  ambiguity.c:
"ambiguity.c", line 64: error: ambiguous argument for operator +():  void (Double , Double ) and  void (Float , Float )
"ambiguity.c", line 64: warning: result of + expression not used
1 error

(Line 64 is the b+i expression.)

The warning is obvious, but I do not understand the error.  Why won't the 
compiler choose to convert variable b to Int and then use the operator+ for
Ints?  The second argument is an exact match for an Int.

If I replace the constructors (like Double::Double(Byte);) with operators 
(like Byte::operator(Double)), the problem is the same.

Will anyone give me some advice?
Please respond via e-mail (and to the net if you wish, of course).

David R. Cok, Eastman Kodak Company, 716-477-7086
e-mail: cok@Kodak.COM