VC++MFC编程出错:关于CArray数组

来源:百度知道 编辑:UC知道 时间:2024/06/12 10:49:35
使用CArray数组时

struct stepnc
{
int id;
CString name;
CArray <CString,CString&> attribute;
};

void CAbcdDlg::OnAa()
{
CArray <stepnc,stepnc&> nc;
stepnc nc1;
nc1.id=0;
nc1.name="测试1";
nc1.attribute.Add(CString("测试11"));
nc1.attribute.Add(CString("测试12"));
nc1.attribute.Add(CString("测试13"));

nc.Add(nc1);
MessageBox(nc[0].attribute[0]);

}
出现这样问题:Compiling...
abcdDlg.cpp
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(443) : error C2582: 'stepnc' : 'operator =' function is unavailable
c:\program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CArray<struct stepnc,struct stepnc &>::SetAtGrow(int,struct stepnc &)'

你这个是CArray的嵌套, 外层CArray里的成员函数SetAtGrow用到了"="; 里层CArray类没有"="这个重载函数,所以你不能用"="赋值;
例如:CArray <CString,CString&> a, b; a = b; 这是不对的.

给你两种思路:
1.重载CArray 里的"="函数.
2.要不你改下 CArray <stepnc,stepnc&> nc;试试用指针代替:CArray <stepnc*,stepnc*> nc;