Article ID: 130276
Article Last Modified on 7/5/2005
/* Compile options required: none
*/
template<class T>
class M {
public:
T m;
};
template<class T>
M<T> f1(const M<T>& x) {return x;}
template<class T>
M<T>& f2(const M<T>& x) {return x;}
void test(void)
{
M<int> x;
M<int> y = f1(x); // errors C2065 & C2064
M<int> z = f2(x); // no error
}
NOTE: Although this has been fixed under Visual C++ 4.0, the definition of
function f2:
template<class T>
M<T>& f2(const M<T>& x) {return x;}
causes the following compilation errors:
To avoid this, the return value of that statement should be casted
appropriately, as follows:
M<T>& f2(const M<T>& x) {return (M<T>&)x;}
Additional query words: 2.00 2.10 9.00 9.10
Keywords: kbbug kbfix kbcpponly kbcompiler KB130276