``void CClistDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
CList point3d;
for (int i = 0; i < 10; i++)
{
point3d.AddTail(CPoint3d( i*100,i*10,i));
}
m_edit_text.Empty();
//POSITION pos = point3d.Find(CPoint3d(100,10,1)); //clist调用find时需要在clist头文件中写上运算符重载
//point3d.RemoveAt(pos);
CString s;
POSITION pos1 = point3d.GetHeadPosition();
for (int i = 0; i < 10; i++)
{
CPoint3d point = point3d.GetNext(pos1);
s.Format(_T("x=%d,\ty=%d,\tz=%d"), point.x, point.y,point.z);
m_edit_text.Append(s);
m_edit_text.Append(_T("\r\n"));
}
UpdateData(false);
}
`
#pragma once
class CPoint3d
{
public:
int x, y, z = 0;
CPoint3d() { };
CPoint3d(int xpos,int ypos,int zpos)
{
x = xpos;
y = ypos;
z = zpos;
};
bool operator==(CPoint3d point)const
{
return (x == point.x&&y == point.y&&z == point.z);
}
};
如图所示,如果在代码中 //POSITION pos = point3d.Find(CPoint3d(100,10,1)); //clist调用find时需要在clist头文件中写上运算符重载
//point3d.RemoveAt(pos);不屏蔽这两行就会报错,求大佬解释下原因
貌似并不是没检索到的问题
point3d.SetAt(pos,CPoint3d(999,99,9));如果使用setat函数则不会报错,并且程序执行正常