FIX: typedef Class Template Causes Compiler Errors C2440/C2561Last reviewed: September 18, 1997Article ID: Q129783 |
2.00 2.10
WINDOWS NT
kbtool kbfixlist kbcode
The information in this article applies to:
SYMPTOMSCompiling a program that has all of the following in the code causes the compiler to generate two errors:
error C2440 : 'return' : cannot convert from 'class B*' to 'class A*' error C2561 : 'f' : function must return a value CAUSEThe 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.
RESOLUTIONUse any one of the following three workarounds:
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 to Reproduce Problem
/* Compile options needed: none */class A {}; template < class T > class C { public : A* f( T *t ) { return t; }}; class B; typedef C<B> CB;
// Work around #1: Move the following line, the definition of class B, // before the typedef which depends on class Bclass B : public A {};
|
Additional reference words: 2.00 2.10 9.00 9.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |