[g++ 2.95.2] template and assignment operator

Alexandre Duret-Lutz alexandre.duret@greyc.ismra.fr
Thu Nov 4 08:58:00 GMT 1999


Hi people,

I can't decide wether this is bad or not. Consider:

#include <iostream>

template< typename T >
struct A {
  template< typename U >
  A<T>& operator=( const U& u ) {
    cout << "hello" << endl;
    return *this;
  }
};

int main()
{
  A<char> a,b;
  
  a = 1;    //  prints "hello"
  a = b;    //  prints nothing
}

For this last instruction, it look like the default assignment
operator was prefered to the template.  Is this behaviour really
correct? I can't see why.

Regards,
-- 
Alexandre Duret-Lutz



More information about the Gcc-bugs mailing list