I have this structure:
struct S_SPECIAL_EVENT
{
BOOL bEventAllDay{};
friend CArchive& operator<<(CArchive& rArchive, S_SPECIAL_EVENT const& rsSE)
{
const WORD wVersion = 1;
return rArchive << wVersion
<< gsl::narrow<bool>(rsSE.bEventAllDay);
}
friend CArchive& operator>>(CArchive& rArchive, S_SPECIAL_EVENT &rsSE)
{
WORD wVersion{};
rArchive >> wVersion;
rsSE.bEventAllDay = readAndCast<BOOL, bool>(rArchive);
return rArchive;
}
};
I tried adding the two serialize operators. But I get compile errors like:
error C3861: 'readAndCast': identifier not found
The method in question is defined in the application header:
// See: https://stackoverflow.com/a/58746336/2287576
template <typename T, typename U>
T readAndCast(CArchive& ar) {
U x;
ar >> x;
return static_cast<T> (x);
}
I have included that header in my file. So why won't it complile?
I changed my code to do things manually:
friend CArchive& operator>>(CArchive& rArchive, S_SPECIAL_EVENT &rsSE)
{
WORD wVersion{};
bool bData{};
rArchive >> wVersion;
rArchive >> bData;
rsSE.bEventAllDay = gsl::narrow<BOOL>(bData);
return rArchive;
}
But I would like to know the answer to the original question.