Re: CMap in CMap
Giovanni Dicanio a ?crit :
I think the problem is that CMap derives from CObject, and CObject
declares *private* copy constructor and operator=.
In fact, if you go to the CObject definition in <afx.h> MFC header file
(at least in VS2008) you can read:
<code>
...
private:
CObject(const CObject& objectSrc); // no implementation
void operator=(const CObject& objectSrc); // no implementation
...
</code>
So, CMap doesn't offer a copy semantic "out of the box".
I would suggest you to use STL std::map container, which is designed in
a way to implement copy semantic out-of-the-box.
In particular, your CMap's:
CMap <int, int, CIAMMetaDataAttribute,
CIAMMetaDataAttribute>EvtAttributes;
CMap <int, int, int, int> alternateValue;
could be substitued by the following std::map's:
std::map< int, CIAMMetaDataAttribute > EvtAttributes;
std::map< int, int, > alternateValue;
Note that std::map does not have the (IMHO) confusing ARG_KEY and
ARG_VALUE templates.
std::map just has the Key and Type template arguments (in its basic form):
map Class (Standard C++ Library)
http://msdn.microsoft.com/en-us/library/s44w4h2s%28VS.80%29.aspx
HTH,
Giovanni
Hi Giovanni,
thanks for the tip.
In the meantime, I managed to solve my problem by declaring a pointer to
the second CMap instead of the CMap itself.
i.e:
******* IAMMetaDataAttribute.h **********
#pragma once
class CIAMMetaDataAttribute
{
public:
CIAMMetaDataAttribute(void);
~CIAMMetaDataAttribute(void);
CString m_name;
bool m_multiValued;
CString m_transform;
CString resourceId;
CMap <int, int, int, int> *alternateValue;
};
So I guessed I could get out with it this way... but your post about the
std::map object puzzled me ;)
Could you tell me more about this std::map thing? Is it more efficient
than CMap? It seems to be less convenient to manipulate, isn't it?
Thanks again for your help.
Fred