PRB: C2440 Error When Using CMap and User Defined Key Type (158541)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
This article was previously published under Q158541 SYMPTOMS
When using the Cmap-templated collection class with a user-defined
class as the data type for key arguments, the compiler generates
the following compiler error:
afxtempl.h(97) : error C2440: 'abstract declarator' :
cannot convert from 'class CClass' to 'unsigned long'
where CClass is the name of the user-defined class.
CAUSE
The default implementation of CMap's HashKey function takes an DWORD
(unsigned long) as a parameter. The compiler does not know how to convert
from a user-defined class type to an unsigned long.
RESOLUTION
Create a static template function to generate a custom HashKey value.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 10/24/2003 |
---|
Keywords: | kbCollectionClass kberrmsg kbprb kbtemplate KB158541 |
---|
|