Trying to save and load a CMap. I thought I could just call the SerializeElements. But everybody seams to overload the SerializeElements why is that necsesary? I have not seen one single example of a call to the function.
SerializeElements takes the size of the CMap as input argument. But how do I know the size of the CMap when I load a CMap from a file?
void CGsdoc_b1Doc::Serialize(CArchive& ar)
int size = m_UserMap.GetCount();
// TODO: add storing code here
Now I have put a override function for SerializeElements in the Document implementation. SerializeElements function is called like above in the Serialize function in the Document. But when I debug the code I never end up in the override function. Have I placed the override function in the wrong file maybee?
template <> void AFXAPI SerializeElements <CUser> ( CArchive& ar, CUser* pNewUser, int nCount )
for ( int i = 0; i < nCount; i++, pNewUser++ )
// Serialize each CPerson object
pNewUser->Serialize( ar );
I think I should derive a class from CMap and implement the override function there. In my project I have four Maps storing different types of objects. So now I have to derive four classes from CMap or?
Now it almost work when I override the SerializeElements in the Document. I have tried to put it in CUser but I got a lot of linking errors. The problem now is that when a CUser is restored by calling its Serialize() function from the SerializeElements() function I want to a add this restored CUser element to the Map. But the compiler complains that the Map is undefined though it is owned by the Document.
Also I dont understand how the next position in the Map can be reached just by incrementing a CUser pointer.
Here is the code from the Document,
void AFXAPI SerializeElements(CArchive& ar, CUser* pUser,int nCount)
for ( int i = 0; i < nCount; i++, pUser++ )
pUser->Serialize( ar ); //restore CUser object
m_UserMap[pUser->GetUserName] = *pUser;//Add User to Map