Re: Enum serialization
enum is a "short" type, so all you have to do is cast your enum value to
short while serializing, and from short to enum while deserializing.
ar << (short)m_element;
ar >> value;
m_element = (Elementi)value;
You can also add an overloaded << or >> operator to your class that is
derived from CArchive:
class CMyArchive : public CArchive
CMyArchive& operator << ( const Elementi& value )
CArchive::operator << ((short)value);
CMyArchive& operator >> ( Elementi& value )
CArchive::operator >> (shValue);
value = (Elementi)shValue;
redefine the document's Serialize() as
void CMyDoc::Serialize( CMyArchive& ar )
But this looks like a hassle...
"Marco Biagioni" <email@example.com> wrote in message
I take an error trying serialize a member in document class of type enum...
binary '>>' : no operator found which takes a right-hand operand of type
'Elementi' (or there is no acceptable conversion)
where i defined
enum Elementi m_element;
and for example m_element = Line;
so in serialize doc function i have in my serialize function...
ar << m_color // Store the current color
<< m_element // the current element type, !!!THIS LINE GIVES NO ERROR!!!
<< m_PenWidth // and the current pen width
<< m_DocSize; // and the current document size
ar >> m_color // Retrieve the current color
m_element // the current element type, !!!ERROR IN THIS LINE!!!
m_PenWidth // and the current pen width
m_DocSize; // and the current document size
Maybe i should implement a personalized operator overload for >> ?
And how should i implement that?And where?
Why << operator doesn't give me the error and works fine?