一、MFC串行化数据和C++对象【2】
保存电话号码和姓名信息。
CObList m_PhoneList;
OnNewDocument()//初始化数据
{
CPhone* pPhone = new CPhone();//CPhone类数据
pPhone->m_Name = "";
pPhone->m_Phone = "";
m_PhoneList.AddHead(pPhone);//加入到CObList链表中去
}
virtual void DeleteContents() //新建文档时,会擦除数据
{
delete m_PhoneList.RemoveHead();
}
m_PhoneList.Serialize(ar) //在C**Document::Serialize()添加,即可保存
//C**View中
POSITION m_positon;
CObList* m_pList;
//CPhone类中的序列化CObject派生
IMPLEMENT_SERIAL(CPhone,CObject,0);
if(ar.IsStoring())
{
ar<<m_Name<<m_Phone;
}
二、vc实验报告链表序列化
界面如下: