O'Reilly logo

Software Engineering and Computer Games by Rudy Rucker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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()) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required