g++: operator T() const

verhoyen pierre-ot//cc 81866- pierre.verhoyen@cnes.fr
Mon Jan 25 10:03:00 GMT 1999


Dear Sir,

Using g++ version egcs-2.91.60 19981201 (egcs-1.1.1 release),
the following minimal program doesn't compile with messages:

A.C:22: no match for `-A<int> &'
A.C:23: no match for `A<int> & + int'

while it _does_ compile with other compilers or with g++ when
removing the T() const operator!

Isn't this a problem of g++ ?

Best regards,

Pierre Verhoyen



template< class T >
class A {
public:
   operator T() {
      return _aT;
   }
   operator T() const {  // Compiles when removing this operator!
      return _aT;
   }
   T& operator=(const T& aT) {
      _aT = aT;
      return _aT;
   }
private:
   T _aT;
};

int main() {
   A<int> a;
   a = 1;
   a = -a;        // ?
   a = a + 1;     // ?
}



More information about the Gcc-bugs mailing list