29.7. Serializing child classes

If you have a child class of an existing class with a Serialize method, you will in fact inherit a serviceable Serialize method. And if you have put the correct DECLARE_SERIAL macro in your *.h and IMPLEMENT_SERIAL in your *.cpp, the inherited Serialize code will save and load the right kinds of child class objects.

If your child class has some new members then you need to override the Serialize method by adding this line to the class declaration: virtualvoid Serialize(CArchive& ar), and by then implementing the method in the code.

For instance our cCritterBullet class includes a new _hitstrength field, and a few other things, so we override its Serialize method to save and load this data. When overriding a

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.