This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with ambiguous overloaded operators
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Arthur Schwarz <aschwarz1309 at att dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 7 Jun 2012 18:52:49 +0100
- Subject: Re: Problem with ambiguous overloaded operators
- References: <1339088953.68518.YahooMailRC@web180814.mail.gq1.yahoo.com>
On 7 June 2012 18:09, Arthur Schwarz wrote:
>
>
> I am using g++ 4.5.3 as my compiler and NetBeans 7.1.2 as my IDE.
>
> What I wnat to do is to overload operators using all selected types. ?What I get
> are error messages indicating that the usage is ambiquous. I ?understaad that
> the runtime usage may be ambiguous using literal values.
Literals are not run-time values, they are compile-time values, a call
using a literal must be resolved at compile-time like any other call.
>?I don't understand why
> a typed variable would cause ambiguity. And I ?would like to know how to code
> around the issue. The issue (to me) is ?that char can be widened to long, and
> unsigned char can be widened to ?unsigned long, but how do I take care of issues
> between unsigned (char ?or long) and signed (char or long) since their ranges
> are different.
A long can be converted to any of the types you have overloaded the
function for, there is no "hierarchy" of types that a long would
prefer to convert to.
You should overload the function for all types you need it for or
explicitly convert the argument to one of the types you have
overloaded the function for.