我的定义结构:
struct Unit
{
CString sName;
public:
Unit & operator=(const Unit &other)
{
if (this == &other) {
return *this;
}; sName = other.sName;
return *this;
};
}; struct Group
{
char szKey[GI_M_CRYPTSIZE];
CArray<Uint, Unit&> ary;
public:
         Group & operator=(const Group &other)
{
if (this == &other) {
return *this;
}; strcpy(szKey, other.szKey);
                            ary = other.ary;

return *this;
};
};但是编译有错,为什么?

解决方案 »

  1.   

    Group & operator=(const Group &other)
    {
    if (this == &other) {
    return *this;
    };/////去掉分号 strcpy(szKey, other.szKey);
                                ary = other.ary;

    return *this;
    };
      

  2.   

    error C2582: 'CArray<struct CTmpDiskIDDlg::Unit,struct CTmpDiskIDDlg::Unit &>' : 'operator =' function is unavailable
      

  3.   

    需要在struct CTmpDiskIDDlg中重载=操作符。
      

  4.   

    刚才看错了,上面那个解释是不对的。更正:
    可能错误是:
    struct CTmpDiskIDDlg::Unit不是在class CTmpDiskIDDlg中以public方式暴露出来。
    导致其它地方不能范围unit的“=”操作符。
      

  5.   

    我的CTmpDiskIDDlg类是以public的形式定义Unit结构的,而且我还没有在其他地方用Unit(只是定义就编译通不过)
      

  6.   

    struct Unit
    {
    CString sName;
    public:
    Unit & operator=(const Unit &other)
    {
    if (this == &other) {
    return *this;
    };////去掉; sName = other.sName;
    return *this;
    };////去掉;
    };下同