我定义了
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)
*/

解决方案 »

  1.   

    未定义拷贝构造函数
    class A
    {
    public:
       
        A(A& other);
    };
      

  2.   

    //就是这段代码用到了 '=' (这是CArray的Copy)template<class TYPE, class ARG_TYPE>
    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++;//问题在这,为什么会这样呢?
    }
      

  3.   

    A& A::operator=(const A& other)
    {
        m_data = other.m_data;
        return *this;
    }
      

  4.   

    *(pDest++) = *(pSrc++);
    这个答案说sorry,是错的。