class CSnakeRect:public CObject
{
public:
int x;
int y;
int orient;
CRect r;
CSnakeRect();
CSnakeRect(const CSnakeRect&);
CSnakeRect operator =(const CSnakeRect &c)
{
x=c.x;
y=c.y;
orient=c.orient;
r=c.r;
return *this;
}
};CSnakeRect::CSnakeRect(const CSnakeRect& right)
{
x=right.x;
y=right.y;
orient=right.orient;
r=right.r;
}基础打得不好呀,请各位大侠援手,错误提示如下:Linking...
snakeDlg.obj : error LNK2005: "public: __thiscall CSnakeRect::CSnakeRect(class CSnakeRect const &)" (??0CSnakeRect@@QAE@ABV0@@Z) already defined in snake.obj
snakeDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall CSnakeRect::CSnakeRect(void)" (??0CSnakeRect@@QAE@XZ)
Debug/snake.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

解决方案 »

  1.   

    operator=应该返回一个类型的引用。
    另外能不能把你其他的代码也贴出来,因为链接出错信息提示你的默认构造和拷贝构造也有问题。
      

  2.   

    to 小虫 应该不是在同一个文件吧
    哈to楼上 operatoer = 就是返回 *this啊
      

  3.   

    楼上的是正确的 我说错了
    CSnakeRect operator =(const CSnakeRect &c)
    {
    x=c.x;
    y=c.y;
    orient=c.orient;
    r=c.r;
    return *this;
    }
     -- >> CSnakeRect& operator =(const CSnakeRect &c)
      

  4.   

    to all:多谢大家,没有说明清楚请原谅.代码都在同一个文件中,我直接在另一个类的.h文件中定义了这个类.刚才我把代码:
    CSnakeRect::CSnakeRect(const CSnakeRect& right)
    {
    x=right.x;
    y=right.y;
    orient=right.orient;
    r=right.r;
    }
    改成为类定义内实现就通过了,改完后的代码如下:
    class CSnakeRect:public CObject
    {
    public:
    int x;
    int y;
    int orient;
    CRect r;
    CSnakeRect()
    {
    x=0;
    y=0;
    orient=1;
    r=CRect(0,0,1,1);
    }
    CSnakeRect(const CSnakeRect &right)
    {
    x=right.x;
    y=right.y;
    orient=right.orient;
    r=right.r;
    }
    CSnakeRect operator =(const CSnakeRect &c)
    {
    x=c.x;
    y=c.y;
    orient=c.orient;
    r=c.r;
    return *this;
    }
    };现在LINK通过了,但是真是不清楚为什么?为什么???????????????????