关于CArray

来源:百度知道 编辑:UC知道 时间:2024/05/31 16:02:24
首先我定义了一个类Point3,
CArray<Point3, Point3> nPoint;
CArray<Point3, Point3> mPoint;
如果nPoint已经被初始化了,现在我想把nPoint的内容赋给mPoint
我直接mPoint=nPoint 可以吗?
我试了下,好像不行,报错如下
Error 1 error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject' c:\program files\microsoft visual studio 8\vc\atlmfc\include\afxtempl.h 272
为什么会报错?请问如何解决?

你在Point3的类中重载操作符'='就行,记得是public的
public:
Point3& operator=(const Point3& src)
{
m_xxx = src.m_xxx;//在这里把=要进行的操作,比如复制什么的写进来
return *this;
}