void CTestView::OnMenuAdd()
{
// TODO: Add your command handler code here
DataInput dlg ;
int i = 0 ;
if(dlg.DoModal() == IDOK)
{
i = dlg.m_Input ;
}
list->AddTail(new CAge(i));
GetDocument()->UpdateAllViews(NULL);
}
void CTestView::OnMenuDeleted()
{
// TODO: Add your command handler code here
DataInput dlg ;
int i = 0 ;
if(dlg.DoModal() == IDOK)
{
i = dlg.m_Input ;
}
//循环遍历查找, 微软说这样安全
POSITION pos1, pos2;
CObject* pa;
for (pos1 = list->GetHeadPosition(); (pos2 = pos1) != NULL;)
{
if (*(CAge*)list->GetNext(pos1) == CAge(i))
{
pa = list->GetAt(pos2); // Save the old pointer for .
list->RemoveAt(pos2);
delete pa; // Deletion avoids memory leak.
}
}
GetDocument()->UpdateAllViews(NULL);
}