Bug in implicit conversion (gcc 3.4.1)?
Boris von Loesch
vonloesch@gmail.com
Thu Aug 26 16:05:00 GMT 2004
Hello,
with gcc 3.3 I have compiled this program successful:
template <class T> class BasisF;
template <class T> inline bool operator<=(const BasisF<T> &a, const
BasisF<T> &b){return a.x <= b.x;}
template<class T> class BasisF{
public:
T x;
BasisF(const T &_x = T()): x(_x){}
BasisF(const BasisF &_b): x(_b.x){}
~BasisF(){}
BasisF& operator= (const T &_x){
x = _x;
return *this;
}
friend bool operator<=<>(const BasisF &a, const BasisF &b);
};
#define min(a,b) ((a) <= (b) ? (a) : (b))
int main(){
BasisF<double> t(1);
if (min(t,2.0)<=0) return 1;
return 0;
}
With gcc 3.4.1 (mingw) I get this error:
g++ -O0 -g3 -Wall -c -oTestp.o ../Testp.c
../Testp.c: In function `int main()':
../Testp.c:26: error: no match for 'operator<=' in 't <= 2.0e+0'
If I move the operator implementation into the class, it works:
template<class T> class BasisF{
...
friend bool operator<=(const...,...){ return a.x<=b.x; }
};
Is this a bug? How can I get the first version to work?
Regards,
Boris
More information about the Gcc
mailing list