29.4. Serializing an array of pointers

The most important part about the Pop Framework’s serialization code is one single line in the cGame::Serialize method:

_pbiota->Serialize(ar); 

Getting that line to work was quite a task. Why? The _pbiota object is a CTypedPtrArray<CObArray, cCritter*> of pointers, some of which point to cCritter objects and some of which point to objects of child class types such as cCritterBullet, cCritterArmed, cCritterArmedPlayer, and the like. The array template type CTypedPtrArray<CObArray, cCritter*> is defined by MFC as an alternative to the simpler template type CArray<cCritter*, cCritter*>.

First of all, we need to tell the cCritter class and its subclasses how to write and read their data; we do that by implementing ...

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.