FIX: C2065 Error on Functions Returns Template Class By ValueLast reviewed: September 18, 1997Article ID: Q130276 |
2.00 2.10
WINDOWS NT
kbtool kbfixlist
The information in this article applies to:
SYMPTOMSAny reference to a template function that returns a template class by value generates these errors:
error C2065: 'function name' : undeclared identifier error C2064: term does not evaluate to a function C2065 RESOLUTIONModify the function to return a reference to the template class instead of returning by value. In the "Sample Code" section of this article, function 'f1' returns a template class by value and fails. Function 'f2' returns atemplate class by reference and succeeds.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was fixed in Microsoft Visual C++, 32-bit Edition, version 4.0.
MORE INFORMATION
Sample Code
/* 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:
error C2446: [*] 'return' : no conversion from 'const class M<int>' to 'class M<int> &' (new behavior; please see help) error C2561: 'f2' : function must return a valueTo 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 reference words: 2.00 2.10 9.00 9.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |