1

I have this existing function:

// 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);
}

It works fine for code like:

m_iReminderUnitType = readAndCast<int, DWORD>(ar);

Where m_iReminderUnitType is of type int.

Today I added a new enum class to my project:

enum class VideoConferenceEventType
{
    Recorded,
    Live
};

And I have a variable of that type and I tried to read it in a similar way:

m_eVideoconfType = readAndCast(VideoConferenceEventType, DWORD > (ar);

It won't work and says the type name is not allowed. This surprised me because in reality this enum class is an int.. How do I fix this?

At the moment I am doing it manually:

if (m_dwVersion >= MSA_VERSION_210061)
{
    DWORD dwData;
    ar >> dwData;
    m_eVideoconfType = static_cast<VideoConferenceEventType>(dwData);
    //m_eVideoconfType = readAndCast(VideoConferenceEventType, DWORD > (ar);
}

I would prefer to use my readAndCast method.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

0 Answers0