首先来看微软原文
template< class TYPE, class ARG_TYPE = const TYPE& >
class CList : public CObject
TYPE
Type of object stored in the list.
ARG _ TYPE
Type used to reference objects stored in the list. Can be a reference.
首先大家明白一点,CList就是一个 链表
然后,需要知道 如何定义并且使用
这里是一个简单的例子
#include "stdafx.h"
#include <afxtempl.h>
int main(int argc, char* argv[])
{
CList <int,int> nList;
{
for (int i = 0 ; i < 10; i++ )
{
nList.AddTail(i);
}
POSITION pos = nList.GetHeadPosition();
while(pos)
{
printf("%d - ",nList.GetNext(pos));
}
printf("\r\n");
}
return 0;
}
大家可以自己运行一下,我每次都试图用最简单的例子来说明问题
接下来,我在给出一个例子
#include "stdafx.h"
#include <afxtempl.h>
int main(int argc, char* argv[])
{
CList <int*,int*> nList;
int nArry[10]={0};
{
for (int i = 0 ; i < 10; i++ )
{
nArry[i] = i;
nList.AddTail(nArry+i);
}
POSITION pos = nList.GetHeadPosition();
while(pos)
{
printf("%d - ",*nList.GetNext(pos));
}
printf("\r\n");
}
return 0;
}
通过两个简单的例子,大家可以初步了解这个东西,,剩下的大家可以参照别人写的例子!