Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
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.

CArchive::SerializeClass

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

void SerializeClass( 
   const CRuntimeClass* pClassRef  
);

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 
{
   DECLARE_SERIAL(CBaseClass);
};
class CDerivedClass : public CBaseClass
{
public:
   virtual void Serialize(CArchive& ar);
};
void CDerivedClass::Serialize(CArchive& ar)
{
   if (ar.IsStoring())
   {
      //normal code for storing contents  
      //of this object
   }
   else
   {
      //normal code for reading contents  
      //of this object
   }

   //allow the base class to serialize along  
   //with its version information
   ar.SerializeClass(RUNTIME_CLASS(CBaseClass));
   CBaseClass::Serialize(ar);
}

Header: afx.h

Community Additions

ADD
Show:
© 2015 Microsoft