Bug report

Philippe Bouchard boucp00@DMI.USherb.CA
Tue Aug 31 22:45:00 GMT 1999


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 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