我定义了
class A
{
public:
A(int data);
A& operator=(A& other);
int m_data;
};A& A::operator=(A& other)
{
m_data = other.m_data;
return *this;
}
A::A(int a)
{
m_data = data;
}然后
CArray<A,A> a;
a.Add(A(1));
a.Add(A(2));CArray<A,A> b;
b.Copy(a); //说我此句有错, =没定义
/*
binary '=' : no operator defined which takes a right-hand operand of type 'const class CA' (or there is no acceptable conversion)
*/
class A
{
public:
A(int data);
A& operator=(A& other);
int m_data;
};A& A::operator=(A& other)
{
m_data = other.m_data;
return *this;
}
A::A(int a)
{
m_data = data;
}然后
CArray<A,A> a;
a.Add(A(1));
a.Add(A(2));CArray<A,A> b;
b.Copy(a); //说我此句有错, =没定义
/*
binary '=' : no operator defined which takes a right-hand operand of type 'const class CA' (or there is no acceptable conversion)
*/
class A
{
public:
A(A& other);
};
void CArray<TYPE, ARG_TYPE>::Copy(const CArray& src)
{
ASSERT_VALID(this);
ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
CopyElements<TYPE>(m_pData, src.m_pData, src.m_nSize);
}template<class TYPE>
AFX_INLINE void AFXAPI CopyElements(TYPE* pDest, const TYPE* pSrc, int nCount)
{
ASSERT(nCount == 0 ||
AfxIsValidAddress(pDest, nCount * sizeof(TYPE)));
ASSERT(nCount == 0 ||
AfxIsValidAddress(pSrc, nCount * sizeof(TYPE))); // default is element-copy using assignment
while (nCount--)
*pDest++ = *pSrc++;//问题在这,为什么会这样呢?
}
{
m_data = other.m_data;
return *this;
}
这个答案说sorry,是错的。