CTypedPtrList Class
来源:互联网 发布:会计记账软件多少钱 编辑:程序博客网 时间:2024/05/16 07:31
Provides a type-safe "wrapper" for objects of class CPtrList.
template< class BASE_CLASS, class TYPE >
class CTypedPtrList : public BASE_CLASS
Parameters
- BASE_CLASS
Base class of the typed pointer list class; must be a pointer list class (CObList or CPtrList).
- TYPE
Type of the elements stored in the base-class list.
When you use CTypedPtrList rather than CObList or CPtrList, the C++ type-checking facility helps eliminate errors caused by mismatched pointer types.
In addition, the CTypedPtrList wrapper performs much of the casting that would be required if you used CObList or CPtrList.
Because all CTypedPtrList functions are inline, use of this template does not significantly affect the size or speed of your code.
Lists derived from CObList can be serialized, but those derived from CPtrList cannot.
When a CTypedPtrList object is deleted, or when its elements are removed, only the pointers are removed, not the entities they reference.
For more information on using CTypedPtrList, see the articles Collections and Template-Based Classes.
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)
};
//===================
//CMyObject.cpp
#include "stdafx.h"
#include "CMyObject.h"
IMPLEMENT_SERIAL(CMyObject, CObject, 0)
void CMyObject::Serialize(CArchive& ar)
{
CObject::Serialize( ar );
if( ar.IsStoring() )
ar << i;
else
ar >> i;
}
Header: afxtempl.h
Tasks
COLLECT Sample: Illustrates MFC Collection ClassesReference
Hierarchy ChartCPtrList Class
CObList Class
Other Resources
CTypedPtrList Members- CTypedPtrList Class
- CTypedPtrList
- CTypedPtrList
- CTypedPtrList
- CTypedPtrList
- CTypedPtrList
- 'GetHeadPosition' : is not a member of 'CTypedPtrList<class CObject,class CLetter *>'
- CTypedPtrArray CTypedPtrList
- CTypedPtrArray CTypedPtrList
- CTypedPtrList详细说明和具体用法
- mfc CtypedPtrList链表的使用
- CTypedPtrList详细说明和具体用法
- CTypedPtrList详细说明和具体用法
- CArray和CTypedPtrList的使用初步
- CTypedPtrList<base_class, ele_class>,特定指针类型的模板
- class
- class
- class
- 转 虚拟机上Redhat linux9.0的VMware Tools详细图文教程[整理]
- 点击按键复制指定处内容!
- Jabber服务器部署
- 转 vmware使用
- 转 加载VMware Tools
- CTypedPtrList Class
- Understanding English Education Cd-Rom 1to 5 Cd-ROM
- ASP编程中20个非常有用的例子
- Hacking RSS and Atom
- 如何制作显示桌面按钮
- 求 近代物理实验专业课排课 的算法
- 整理Asp的19个基本技巧
- VS ASP .NET web服务器报HTTP/1.1 500 Server Error错误
- Mastering AutoCAD 2007 and AutoCAD LT 2007