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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.