弱弱的提一个CObList:GetNext的有关问题
弱弱的提一个CObList::GetNext的问题
{
CMFCtest1Doc *pDoc=GetDocument();
m_studentViewlist=&(pDoc->m_studentlist);
m_position=m_studentViewlist->GetHeadPosition();
CStudent *pListDoc1,*pListDoc=(CStudent *)m_studentViewlist->GetAt(m_position);
pListDoc1=(CStudent *)m_studentViewlist->GetNext(m_position);
m_age=pListDoc1->m_age;
m_name=pListDoc1->m_name;
m_num=pListDoc1->m_num;
m_sex=pListDoc1->m_sex;
m_cond=pDoc->m_cond;
UpdateData(FALSE);
}
为什么pListDoc1->m_name和pListDoc->m_name,pListDoc1->m_sex和pListDoc->m_sex,pListDoc1->m_num和pListDoc->m_num,pListDoc1->m_age和pListDoc->m_age都一样?
请高手解析一下!谢谢了
------解决方案--------------------
是移动了,但是返回值是移动之前的。
------解决方案--------------------
只是指针移动了,但是你没有重新获取当前位置的值。要么在GetNext()后面再调用一次GetAt(),要么在GetNext()后再移动一次
{
CMFCtest1Doc *pDoc=GetDocument();
m_studentViewlist=&(pDoc->m_studentlist);
m_position=m_studentViewlist->GetHeadPosition();
CStudent *pListDoc1,*pListDoc=(CStudent *)m_studentViewlist->GetAt(m_position);
pListDoc1=(CStudent *)m_studentViewlist->GetNext(m_position);
m_age=pListDoc1->m_age;
m_name=pListDoc1->m_name;
m_num=pListDoc1->m_num;
m_sex=pListDoc1->m_sex;
m_cond=pDoc->m_cond;
UpdateData(FALSE);
}
为什么pListDoc1->m_name和pListDoc->m_name,pListDoc1->m_sex和pListDoc->m_sex,pListDoc1->m_num和pListDoc->m_num,pListDoc1->m_age和pListDoc->m_age都一样?
请高手解析一下!谢谢了
------解决方案--------------------
是移动了,但是返回值是移动之前的。
------解决方案--------------------
只是指针移动了,但是你没有重新获取当前位置的值。要么在GetNext()后面再调用一次GetAt(),要么在GetNext()后再移动一次