This might sound basic but:
WORD wSong = 0;
CArchive ar;
...
ar >> wSong;
m_sPublicTalkInfo.iSongStart = static_cast<int>(wSong);
At the moment I read the WORD into a specific variable and the cast it.
Can I read it in and cast at the same time?
Please note I can't serialize a int. It must be a WORD and cast to int.
Or
ar >> wSong;
m_sPublicTalkInfo.iSongStart = static_cast<int>(wSong);
I don't think there is a direct way. You could implement a helper function:
It might be better to use the fixed-width integer types in your program, i.e. perhaps
int_least16_tinstead ofintto be sure the type has the right size.WORDis fixed to 16bit, butintisn't. Also,WORDis unsigned andintisn't, so there could be an overflow during casting.