Bug report

Jan Reimers janr@molienergy.bc.ca
Tue Aug 31 22:45:00 GMT 1999


See below.

> ----------
> From: 	Philippe Bouchard[SMTP:boucp00@DMI.USherb.CA]
> Sent: 	Friday, August 20, 1999 12:08 AM
> To: 	
> Subject: 	Bug report
> 
> OK, I have a situation here. 
> I have defined a template wrapper class from which I can only perform
> casts to the template type. 
> In my subclass (class text), I have defined the operator << as taking
> "const text &" and "text &", but the compiler is confused about which
> one of the cast operator to use between the two defined in class gc.
> In this case, it should be smart enough to take the shortest way
> between an object of type gc and a function taking "const text &" and
> "text &". 
> Here is the wrapper class: 
> template <class TYPE> class gc { 
>    ... 
>    operator const TYPE & () const; 
>    operator TYPE & () const; 
Here it appears you are trying to overload based on return type.  This
is not allowed in C++.  

JR
>    ... 
>    }; 
> Here is the subclass: 
> class text { 
>    ... 
>   text(char * const); 
>   friend text & operator << (text &, const text &); 
>    ... 
>    }; 
> Here is the function in question, it should use the "text &" operator
> for the first argument and the "const text &" operator for the second
> one... 
> text & operator << (text &, const text &); 
> int main() { 
>    const gc<text> a; 
>    a << "Some text..."; 
>    ... 
>    } 
> Here's exactly what the compiler is complaining about: 
> testgc.cc: In function `int main()': 
> testgc.cc:14: conversion from `gc<text>' to `const text &' is
> ambiguous 
> gc.h:141: candidates are: gc<text>::operator const text &<text>()
> const 
> gc.h:146:                 gc<text>::operator text &<text>() const 
> gc.h:151:                 gc<text>::operator text &<text>() <near
> match> 
> I am using "g++ testgc.cc -Wall" as the command line. 
> Reading specs from
> /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs 
> gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) 
>   
> Thank you. 
> Philippe.
> 



More information about the Gcc-bugs mailing list