PRB: C2027 When Using MFC Templated Collection ClassesLast reviewed: July 10, 1997Article ID: Q140229 |
4.00
WINDOWS NT
kbprg kberrmsg kbprb
The information in this article applies to:
SYMPTOMSWhen you use MFC templated collection classes such as CArray, CList, and CMap to store elements of type HTREEITEM or HIMAGELIST, the compiler generates the following compiler error:
afxtempl.h(73) : error C2027: use of undefined type '_TREEITEM' -or- afxtempl.h(73) : error C2027: use of undefined type '_TREEITEM' CAUSEHTREEITEM is type-defined (typedef) as struct _TREEITEM, and HIMAGELIST is type-defined (typedef) as struct _IMAGELIST in header file Commctrl.h located in the \Msdev\Include directory. Structures _TREEITEM and IMAGELIST are not defined in any header files or source files. However, the template collection class helper function DestructElements in Visual C++ version 4.0 calls the destructor of the stored elements. In this case, the destructor of structure _TREEITEM or _IMAGELIST. Hence, the compiler error.
RESOLUTIONDefine a dummy structure for _TREEITEM or _IMAGELIST in global scope. For example, the following code should compile cleanly:
// Other includes. #include <afxtempl.h>struct _TREEITEM {}; struct _IMAGELIST {};
void TestFunction(){ // will now not generate the compiler error CArray< HTREEITEM, HTREEITEM > MyArray1; CArray< HIMAGELIST, HIMAGELIST > MyArray2;}
STATUSThis behavior is by design.
|
Additional reference words: 4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |