MFC中的CTypedPtrList 模板怎么用?谢谢
来源:百度知道 编辑:UC知道 时间:2024/05/13 19:50:27
我想用它做个存储点数据的链表~
This example creates an instance of CTypedPtrList, adds one object, serializes the list to disk, and then deletes the object:
typedef CTypedPtrList<CObList, CMyObject*> CMyList;
CMyList ml;
CMyObject* pMyObject = new CMyObject();
ml.AddTail(pMyObject);
CFileException e;
CFile myFile;
myFile.Open("MyFile.txt", CFile::modeCreate|CFile::modeWrite, &e);
CArchive ar(&myFile, CArchive::store);
ml.Serialize(ar);
ar.Close();
myFile.Close();
while (!ml.IsEmpty())
{
delete ml.GetHead();
ml.RemoveHead();
}
//=====================
//where CMyObject is defined by the following files:
//CMyObject.h
class CMyObject : public CObject
{
public:
int i;
void Serialize(CArchive& ar);
CMyObject() { i = 9876;}
protected:
DECLARE_SERIAL(CMyObject)
};
//===================
//CMyOb