编一个类似数据库的程序 自己定义了一个CInfoTable类,里面有一个CList的容器存储一组我自己定义的另一个类CPlayer,
而CPlayer类中又包含一个CList容器。但在写完序列化函数后,打开文件会报错非预期的文件格式。
public:
CList Rectab;
int m_count;
void RecordTable::Serialize(CArchive &ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar<<m_count;
POSITION pos = Rectab.GetHeadPosition();
while(pos!=NULL)
{
(Rectab.GetAt(pos)).Serialize(ar);
Rectab.GetNext(pos);
}
}
else
{
// TODO: add loading code here
if(m_count>0)
{
for(int i=0;i<m_count;i++)
{
Rectab.RemoveTail();
}
}
ar>> m_count;
for(int i=0; i<m_count; i++)
{
Record table;
table.Serialize(ar);
Rectab.AddTail(table);
}
}
}
当将上面函数去掉成:
void RecordTable::Serialize(CArchive &ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar<<m_count;
}
}
else
{
// TODO: add loading code here
ar>> m_count;
}
}
}就不会报出上面的错误 但CList 部分未完成序列化
求教应当怎么改(PS:Record类的序列化不存在问题)