Topic: Strange behavior of member template constructors


Author: Adi Shavit <adish@cs.huji.ac.il>
Date: 1998/01/09
Raw View
Hi,

 Is there a good reason why this code compiles and when I switch the 2
constructors it doesn't? (I'm using Visual C++ 5.0).

This compiles:

template <class T>
class Try
{
public :
 template <class S>
  Try (const Try<S> & t){ _a = (T)t._a ;_b = (T)t._b;}

  Try(const Try<T> &t) : _a(t._a), _b(t._b) {}

 T _a;
 T _b;
};


This doesn't:

template <class T>
class Try
{
public :
  Try(const Try<T> &t) : _a(t._a), _b(t._b) {}

  template <class S>
  Try (const Try<S> & t){ _a = (T)t._a ;_b = (T)t._b;}

 T _a;
 T _b;
};

It says:

error C2535: 'Try::Try(const class Try &)' : member function already
defined or declared

Is this correct or is this a compiler bug?

Thanx Adi.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/01/10
Raw View
Adi Shavit writes:

>  Is there a good reason why this code compiles and when I switch the 2
> constructors it doesn't? (I'm using Visual C++ 5.0).

Yes, MS-VC++ 5.0 is broken :-)

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]