在CTypedPtrList 模板集合类中如何获取列表位置(position)?

来源:百度知道 编辑:UC知道 时间:2024/07/07 16:24:31
一段程序里面需要用到从CTypedPtrList中遍历列表,以寻找某个元素(element),我的想法是先获取该列表的头位置,然后用GetNext()来搜索,但是:
如何获取头位置???
小弟初学,请各路高人指点一二。谢谢!!!!

写了个例子

#include <afxtempl.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
CTypedPtrList< CPtrList, int* > iList;
iList.AddTail( new int(5) );
iList.AddTail( new int(7) );
iList.AddTail( new int(1) );
iList.AddTail( new int(10) );

POSITION pos = iList.GetHeadPosition();
while( pos )
cout << *iList.GetNext( pos ) << endl ;

while( !iList.IsEmpty() )
delete iList.RemoveHead();

return 0;
}