
c++:error C2601: 'main' : local function definitions are illegal
#include<iostream>#include<cmath>usingnamespacestd;classPoint{private:doubleX,Y;publi...
#include<iostream>
#include<cmath>
using namespace std;
class Point{
private:
double X,Y;
public:
Point(double x,double y){X=x;Y=y;}
friend double GetLength(Point A,Point B);
double GetX(){return X;}
double GetY(){return Y;}
};
double GetLength(Point A,Point B)
{ return sqrt(abs(A.GetX()-B.GetX())*abs(A.GetX()-B.GetX())+abs(A.GetY()-B.GetY())*abs(A.GetY()-B.GetY()));
int main()
{ Point A(5,6);
Point B(1,7);
cout<<GetLength(A,B)<<endl;
return 0;
}
------------------------------------------------
D:\studying in college\C++\Point friend.cpp(16) : error C2601: 'main' : local function definitions are illegal
D:\studying in college\C++\Point friend.cpp(21) : fatal error C1004: unexpected end of file found
Error executing cl.exe. 展开
#include<cmath>
using namespace std;
class Point{
private:
double X,Y;
public:
Point(double x,double y){X=x;Y=y;}
friend double GetLength(Point A,Point B);
double GetX(){return X;}
double GetY(){return Y;}
};
double GetLength(Point A,Point B)
{ return sqrt(abs(A.GetX()-B.GetX())*abs(A.GetX()-B.GetX())+abs(A.GetY()-B.GetY())*abs(A.GetY()-B.GetY()));
int main()
{ Point A(5,6);
Point B(1,7);
cout<<GetLength(A,B)<<endl;
return 0;
}
------------------------------------------------
D:\studying in college\C++\Point friend.cpp(16) : error C2601: 'main' : local function definitions are illegal
D:\studying in college\C++\Point friend.cpp(21) : fatal error C1004: unexpected end of file found
Error executing cl.exe. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询