//循环遍历, 微软说这样安全
POSITION pos ;
for (pos = list->GetHeadPosition(); pos != NULL; list->GetNext(pos))
{
CAge* pa = (CAge*) list->GetAt(pos); // Save the old pointer for
str.Format("%d",pa->GetValue()) ;
pDC->TextOut(100, i*20 ,str);
i++;
}
//循环遍历查找, 微软说这样安全
POSITION pos1, pos2;
CObject* pa;
for (pos1 = list->GetHeadPosition(); (pos2 = pos1) != NULL;)
{
if (*(CAge*)list->GetNext(pos1) == CAge(40))
{
pa = list->GetAt(pos2); // Save the old pointer for .
list->RemoveAt(pos2);
delete pa; // Deletion avoids memory leak.
}
}