求助 warning C4518: 'extern ' 错误问题
代码:
#include <iostream>
#include <cmath>
using namespace std;
#define pi 3.141592657
struct circle
{
double x,y;
double r;
}
double dis(circle a,circle b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double interarea(circle a,circle b)
{
double d=dis(a,b);
if(d>=a.r+b.r)
return 0;
else if(d<fabs(a.r-b.r))
{
double r=a.r>b.r?b.r:a.r;
return pi*r*r;
}
else
{
double m=2*acos((a.r*a.r+d*d-b.r*b.r)/(2*a.r*d));
double n=2*acos((b.r*b.r+d*d-a.r*a.r)/(2*b.r*d));
double area1=a.r*a.r*m/2-a.r*a.r*sin(m)/2;
double area2=b.r*b.r*n/2-b.r*b.r*sin(n)/2;
return area1+area2;
}
}
int main()
{
circle a,b;
cout<<"请输入第一个圆的圆心坐标和半径";
cin>>a.x>>a.y>>a.r;
cout<<"请输入第二个圆的圆心坐标和半径";
cin>>b.x>>b.y>>b.r;
double area=interarea(a,b);
cout<<"两个圆相交部分的面积为:"<<area<<endl;
return 0;
}
错误:
Compiling...
两个圆相交部分的面积.cpp
d:\program files\microsoft visual studio\vc98\include\errno.h(29) : warning C4518: 'extern ' : storage-class or type specifier(s) unexpected here; ignored
d:\program files\microsoft visual studio\vc98\include\errno.h(29) : error C2059: syntax error : 'string'
d:\program files\microsoft visual studio\vc98\include\errno.h(29) : error C2143: syntax error : missing ';' before '{'
d:\program files\microsoft visual studio\vc98\include\errno.h(29) : error C2447: missing function header (old-style formal list?)
D:\Program Files\Microsoft Visual Studio\MyProjects\试题一\两个圆相交部分的面积.cpp(17) : error C2628: 'circle' followed by 'double' is illegal (did you forget a ';'?)
D:\Program Files\Microsoft Visual Studio\MyProjects\试题一\两个圆相交部分的面积.cpp(19) : error C2440: 'return' : cannot convert from 'double' to 'struct circle'
No constructor could take the source type, or constructor overload resolution was ambiguous
D:\Program Files\Microsoft Visual Studio\MyProjects\试题一\两个圆相交部分的面积.cpp(24) : error C2440: 'initializing' : cannot convert from 'struct circle' to 'double'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.
[解决办法]
如需要阅读该回复,请登录或注册CSDN!