CArchive::WriteClass
사용 WriteClass 파생된 클래스를 직렬화 하는 동안 기본 클래스의 클래스 및 버전 정보를 저장 합니다.
void WriteClass(
const CRuntimeClass* pClassRef
);
매개 변수
- pClassRef
에 대 한 포인터는 CRuntimeClass 요청 된 클래스 참조에 해당 하는 구조.
설명
WriteClass기록에 대 한 참조는 CRuntimeClass 기본 클래스에 CArchive. 사용 CArchive::ReadClass 에 대 한 참조를 검색 합니다.
WriteClass보관 된 클래스 정보를 런타임 클래스와 호환 되는지 확인 합니다. 호환 되지 않는 경우 WriteClass throw 되는 CArchiveException.
런타임 클래스를 사용 해야 DECLARE_SERIAL 및 IMPLEMENT_SERIAL. 그렇지 않으면 WriteClass throw 되는 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();
}
요구 사항
헤더: afx.h