我的class定义:#include<iostream.h>
#include<math.h>
class Point
{
public:
void Set(double ix,double iy);
double xoffset();
double yoffset();
double angle();
double radius();
protected:
double x;
double y;
};
成员函数定义:#include<iostream.h>
#include"point.h"
void Point::Set(double ix,double iy)
{
x=ix;
y=iy;
}
double Point::xoffset()
{
return x;
}
double Point::yoffset()
{
return y;
}
double Point::angle()
{
return(180/3.14159)*atan2(y,x);
}
double Point::radius()
{
return sqrt(x*x+y*y);
}
主函数:
#include<iostream.h>
#include"point.h"
void main()
{
Point p;
double x,y;
for(;;)
{
cout<<"Enter x and y:"<<endl;
cin>>x>>y;
if(x<0)
break;
p.Set(x,y);
cout<<"angle="<<p.angle()
<<",radius="<<p.radius()
<<",x offset="<<p.xoffset()
<<",y offset="<<p.yoffset()<<endl;
}
}
compile没问题
build后就出现问题了:D:\NO2\point.cpp(4) : error C2084: function 'void __thiscall Point::Set(double,double)' already has a body
D:\NO2\point.cpp(10) : error C2084: function 'double __thiscall Point::xoffset(void)' already has a body
D:\NO2\point.cpp(15) : error C2084: function 'double __thiscall Point::yoffset(void)' already has a body
D:\NO2\point.cpp(20) : error C2084: function 'double __thiscall Point::angle(void)' already has a body
D:\NO2\point.cpp(25) : error C2084: function 'double __thiscall Point::radius(void)' already has a body
Error executing cl.exe.