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