FIX: typedef Class Template Causes Compiler Errors C2440/C2561 (129783)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
This article was previously published under Q129783 SYMPTOMS
Compiling a program that has all of the following in the code causes the
compiler to generate two errors: - Class A.
- Class B derived from class A.
- Template class C that has type T as its argument.
- Class C has a member function that returns a type of A*.
- Type T* value in the return statement of the function.
- Function implementation inside the class C definition.
- "typedef C < B > CB" before the class B definition.
Here are the two errors generated:
error C2440 : 'return' : cannot convert from 'class B*' to
'class A*'
-and-
error C2561 : 'f' : function must return a value
CAUSE
The class template was instantiated within the typedef statement where the
class B definition (the derivation) has not been seen by the compiler yet.
Therefore no conversion is defined between the derived class and the base
class.
RESOLUTION
Use any one of the following three workarounds: STATUS
Microsoft 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.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | 2.00 2.10 kbbug kbcode kbfix KB129783 kbAudDeveloper |
---|
|