CArchive::WriteClass

使用 WriteClass 在派生类中的序列化时存储基类的版本和选件类信息。

void WriteClass(
   const CRuntimeClass* pClassRef 
);

参数

  • pClassRef
    为对应于选件类的 CRuntimeClass 结构的指针引用请求。

备注

WriteClass 写入 CRuntimeClass 的对 CArchive的基类。 使用 CArchive::ReadClass 检索引用。

WriteClass 验证存档的选件类信息与您的运行时选件类兼容。 如果没有CLS,WriteClass 将引发 CArchiveException

您的运行时选件类必须使用 DECLARE_SERIALIMPLEMENT_SERIAL;否则,WriteClass 将引发 CNotSupportedException

可以使用 SerializeClass 而不是 WriteClass,处理选件类读取和写入引用。

示例

CFile myFile(_T("My__test__file.dat"), 
   CFile::modeCreate | CFile::modeReadWrite);

// Create a storing archive.
CArchive arStore(&myFile, CArchive::store);

// Store the class CAge in the archive.
arStore.WriteClass(RUNTIME_CLASS(CAge));

// Close the storing archive.
arStore.Close();

// Create a loading archive.
myFile.SeekToBegin();
CArchive arLoad(&myFile, CArchive::load);

// Load a class from the archive.
CRuntimeClass* pClass = arLoad.ReadClass();
if (!pClass->IsDerivedFrom(RUNTIME_CLASS(CAge)))
{
   arLoad.Abort();                  
}

要求

Header: afx.h

请参见

参考

CArchive选件类

层次结构图

CArchive::ReadClass

CArchive::GetObjectSchema

CArchive::SetObjectSchema

CArchive::SerializeClass

CArchiveException选件类

CNotSupportedException选件类

CObList::CObList