Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Call this member function when you want to store and load the version information of a base class.

void SerializeClass(
   const CRuntimeClass* pClassRef 


A pointer to a run-time class object for the base class.


SerializeClass reads or writes the reference to a class to the CArchive object, depending on the direction of the CArchive. Use SerializeClass in place of ReadClass and WriteClass as a convenient way to serialize base-class objects; SerializeClass requires less code and fewer parameters.

Like ReadClass, SerializeClass verifies that the archived class information is compatible with your runtime class. If it is not compatible, SerializeClass will throw a CArchiveException.

Your runtime class must use DECLARE_SERIAL and IMPLEMENT_SERIAL; otherwise, SerializeClass will throw a CNotSupportedException.

Use the RUNTIME_CLASS macro to retrieve the value for the pRuntimeClass parameter. The base class must have used the IMPLEMENT_SERIAL macro.


class CBaseClass : public CObject { ... };
class CDerivedClass : public CBaseClass { ... };
void CDerivedClass::Serialize(CArchive& ar)
   if (ar.IsStoring())
      //normal code for storing contents 
      //of this object
      //normal code for reading contents 
      //of this object

   //allow the base class to serialize along 
   //with its version information

See Also

CArchive Overview | Class Members | Hierarchy Chart | CArchive::ReadClass | CArchive::WriteClass | CArchive::GetObjectSchema | CArchive::SetObjectSchema | CArchiveException | CNotSupportedException

© 2016 Microsoft