CArray能嵌套CArray吗?
我想在CArray里再套一个CArray,为的是动态扩充内存并填充数据。例如:
struct stB{
CArray<int,int> A;
}
CArray<stB,stB> B;
这些代码编译通过,我在下面写上:
stB b;
b.A.Add(123);
编译通过,再加上一句
b.Add(b);
编译提示:
error C2664: 'Add' : cannot convert parameter 1 from 'struct stB' to 'struct stB'
No copy constructor available for struct 'stB'
说什么没有拷贝构造函数,好,吧stB改一下:
struct stB{
CArray<int,int> A;
stB(stB &a)
{
A.Copy(a.A);
}
}
编译,又告诉我:
error C2512: 'stB' : no appropriate default constructor available
于是我又改成
struct stB{
CArray<int,int> A;
stB(stB &a)
{
A.Copy(a.A);
}
stB()
{}
}
再编译,提示:
program files\microsoft visual studio\vc98\mfc\include\afxtempl.h(443) : error C2582: 'stB' : 'operator =' function is unavailable
d:\program files\microsoft visual studio\vc98\atl\include\atlbase.h(428) : while compiling class-template member function 'void __thiscall CArray<struct stB,struct stB>::SetAtGrow(int,struct stB)'
afxtempl.h里的“=”不能用,还要重载“=”?!
怎么嵌套了一下就引出这么多麻烦?望大家能给我解释其中原委,抑或有更好的方法,不吝赐教,谢谢!