CTypedPtrList Class

 

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.

<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl0332238cd,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl03img,"; </script> RemarksRemarks

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.

<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl06beabbaf,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl06img,"; </script> ExampleExample

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;
}
<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl08b11c326,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl08img,"; </script> RequirementsRequirements

Header: afxtempl.h

<script type="text/Javascript"> var ExpCollDivStr = ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl0908f6018,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl09img,"; </script> See AlsoSee Also
Tasks
COLLECT Sample: Illustrates MFC Collection Classes
Reference
Hierarchy Chart
CPtrList Class
CObList Class
Other Resources
CTypedPtrList Members
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值