The information in this article applies to:
SYMPTOMSIf you are using MFC-templated type safe collection classes, such as CTypedPtrArray, CTypedPtrList, CTypedPtrMap classes or any classes derived from these classes in MFC4.2, and you have a forward declaration of the base classes that are stored as elements in these collection classes, you may get compiler errors similar to the ones listed below depending on which classes are used in the application: - or - See the More Information section below for a reproducible case. CAUSEThe MFC-templated type safe collection classes provided in MFC4.0 and MFC4.1 are not fully type safe. MFC4.2 added more wrapper functions to these classes to make them fully type safe. For example, in MFC4.2 the CTypedPtrList class now contains the following additional wrapper functions that were not in MFC4.0 or MFC4.1:
The implementation of some of these newly-added functions makes calls to
their base class' implementation. For example, CTypedPtrList::AddHead(TYPE
newElement) calls BASE_CLASS::AddHead(newElement) where newElement is
expected to be a pointer to CObject. (BASE_CLASS can be either CObList,
CPtrList, or any classes derived from these two classes for a
CTypedPtrList.)The BASE_CLASS must be derived from CObject or you will get the compiler error C2664. Because there is only a forward declaration of the base class, before instantiating the MFC templated type safe collection class, the compiler has no way to tell if the base class is derived from CObject directly or indirectly, hence the compiler error C2664. RESOLUTIONDefine the base class before instantiating the type safe collection classes. STATUSThis behavior is by design. MORE INFORMATIONThe following sample code demonstrates the problem: Sample Code
You can also reproduce the problem by building step 2 of the Scribble
tutorial from Visual C++ 4.1 using Visual C++ 4.2.For a full list of newly-added functions in classes CTypedPtrList, CTypedPtrArray and CTypePtrMap, please refer to the following Microsoft Knowledge Base article: Q154482 FIX: Undocumented Functions in Type Safe Collection Classes Additional query words: 4.00 4.10 4.20
Keywords : kbnokeyword kbMFC kbVC |
Last Reviewed: July 28, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |