在本教程之后,http://msdn.microsoft.com/en-us/library/vstudio/3bfsbt0t.aspx实现了以下代码:
class Esame: public CObject
{
public:
INT voto;
INT crediti;
BOOL lode;
CString nome;
Esame(){}
Esame(CString nome, INT voto, BOOL lode, INT crediti) :nome(nome), voto(voto), lode (lode), crediti(crediti) {}
void Serialize(CArchive& ar);
protected:
DECLARE_SERIAL(Esame)
};
IMPLEMENT_SERIAL(Esame, CObject, 1)
void Esame::Serialize(CArchive& ar){
CObject::Serialize(ar);
if (ar.IsStoring())
{
ar << voto << lode << crediti;
}
else
{
ar >> voto >> lode >> crediti;
}
}
然后我打电话:
CFile file(_T("file.and"), CFile::modeCreate);
CArchive afr(&file, CArchive::store);
Esame e;
afr << e;
但是我得到了<<运算符,没有找到一个cArchive类型左边的操作符。
发布于 2013-11-25 23:43:52
这是因为您没有为类operator<<
提供过载的Esame
。您所链接的文章也没有这样做,所以您可能打算这样做:
CFile file(_T("file.and"), CFile::modeCreate);
CArchive afr(&file, CArchive::store);
Esame e;
e.Serialize(ar);
因此,直接调用Serialize
函数,类中的实现使用operator<<
序列化所需的基本成员变量,并对其他复杂对象调用Serialize
。
如本教程所示:
void CCompoundObject::Serialize( CArchive& ar )
{
CObject::Serialize( ar ); // Always call base class Serialize.
m_myob.Serialize( ar ); // Call Serialize on embedded member.
m_pOther->Serialize( ar ); // Call Serialize on objects of known exact type.
// Serialize dynamic members and other raw data
if ( ar.IsStoring() )
{
ar << m_pObDyn;
// Store other members
}
else
{
ar >> m_pObDyn; // Polymorphic reconstruction of persistent object
//load other members
}
}
发布于 2014-02-09 03:05:05
afr << &e;
需要指针类型。
https://stackoverflow.com/questions/20207157
复制相似问题