读书人

高手,帮帮忙,该如何解决

发布时间: 2012-02-23 22:01:35 作者: rapoo

高手,帮帮忙
#pragma hdrstop
#include <iostream.h>
//---------------------------------------

#pragma argsused
class point{
int x,y;
public:
point(int vx,int vy)
{
x = vx; y = vy;
}
point(){ x = 0; y = 0;}

point operator + (point p1);
point operator - (point p1);
void print(){cout < <x < < " " < <y < < "\n ";
};
point point::operator + (point p1)
{
point p;
p.x = x + p1.x;
p.y = y + p1.y;

return p;
}
point point::operator - (point p1)
{
point p;
p.x = x - p1.x;
p.y = y - p1.y;

return p;
}
int main(int argc, char* argv[])
{
point p1(10,10),p2(20,20);

p1 = p1 + p2;


return 0;
}

错误提示为:
++ Error] Unit1.cpp(22): E2238 Multiple declaration for 'point::operator +(point) '
[C++ Error] Unit1.cpp(17): E2344 Earlier declaration of 'point::operator +(point) '
[C++ Error] Unit1.cpp(30): E2238 Multiple declaration for 'point::operator -(point) '
[C++ Error] Unit1.cpp(18): E2344 Earlier declaration of 'point::operator -(point) '
[C++ Error] Unit1.cpp(49): E2040 Declaration terminated incorrectly

请问错误出在哪里???谢谢

[解决办法]
好隐蔽的错误:

void print(){cout < <x < < " " < <y < < "\n ";} //少了右大括号

读书人网 >C++ Builder

热点推荐