CArchive::SerializeClass

更新 : 2007 年 11 月

基本クラスのバージョン情報を格納する場合、および読み込む場合に呼び出します。

void SerializeClass(
   const CRuntimeClass* pClassRef 
);

パラメータ

  • pClassRef
    基本クラスのランタイム クラス オブジェクトへのポインタ。

解説

SerializeClass は、CArchive の方向に応じて、クラスへの参照を CArchive オブジェクトに読み込んだり、書き込んだりします。SerializeClass は、ReadClass および WriteClass の代わりに、基本クラス オブジェクトをシリアル化できます。SerializeClass は、使用するコードとパラメータの数が少なくて済みます。

SerializeClass は、ReadClass と同じように、アーカイブされたクラス情報がランタイム クラスに互換性があるかどうかを検証します。互換性がない場合、SerializeClassCArchiveException をスローします。

ランタイム クラスでは、DECLARE_SERIAL および IMPLEMENT_SERIAL を使用する必要があります。使用しない場合、SerializeClassCNotSupportedException をスローします。

RUNTIME_CLASS マクロを使用して、pRuntimeClass パラメータの値を取得します。基本クラスでは、IMPLEMENT_SERIAL マクロを使用する必要があります。

使用例

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);
}

必要条件

ヘッダー : afx.h

参照

参照

CArchive クラス

階層図

CArchive::ReadClass

CArchive::WriteClass

CArchive::GetObjectSchema

CArchive::SetObjectSchema

CArchiveException クラス

CNotSupportedException クラス

その他の技術情報

CArchive のメンバ