MSDN上的语法说明和例子都很全了。 CArray<CPoint,CPoint> myArray;// Add elements to the array. for (int i = 0; i < 10; i++) myArray.Add(CPoint(i, 2*i));myArray.RemoveAt(5);#ifdef _DEBUG afxDump.SetDepth(1); afxDump << "myArray: " << &myArray << "\n"; #endif
简化一下我使用的: class CA { public: ......private: CArray <CB,CB&> m_a; };class CB{ public: ...... private: CPtrArray m_b; };注意类B中的m_b会嵌套了CB的类型指针 数组;
Use this member function to copy the elements of one array to another.
void Copy(
const CArray& src
);
CPtrArray如果是自己分配的指针的话只能一个一个重新分配指针后插入新的CPtrArray,否则也可以调用类似的Copy方法。
CArray<CPoint,CPoint> myArray;// Add elements to the array.
for (int i = 0; i < 10; i++)
myArray.Add(CPoint(i, 2*i));myArray.RemoveAt(5);#ifdef _DEBUG
afxDump.SetDepth(1);
afxDump << "myArray: " << &myArray << "\n";
#endif
class CA
{
public:
......private:
CArray <CB,CB&> m_a;
};class CB{
public:
......
private:
CPtrArray m_b;
};注意类B中的m_b会嵌套了CB的类型指针 数组;