29.3. Serialize, operator<<, and operator>>

Rather than working directly with files in MFC, we work with CArchive objects, which are friendly wrappers that have files buried down inside them. The general process of writing from or reading into a class such as CPopDoc or cCritter gets encapsulated into a method known as Serialize. Serialize is a polymorphic method that’s declared way up inside CObject as virtual void Serialize( CArchive& ar ).

One of the useful things about a CArchive is that it ‘knows’ whether you’re writing to it or reading from it. That is, if you have SomeClass which is perhaps a child of ParentClass, the SomeClass::Serialize function will normally have the form

 void SomeClass::Serialize( CArchive& ar ) { if (ar.IsStoring()) ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.