|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
Point (int x=0,int y=0):x(x),y(y){cout<<"构造函数被调用"<<endl;}
Point (Point &p){cout<<"复制构造函数被调用"<<endl;x=p.x;y=p.y;}
friend double dist(Point &p1,Point &p2);
private:
int x,y;
};
double dist(Point &p1,Point &p2)
{
double x=p2.x-p1.x;
double y=p2.y-p1.y;
return sqrt(x*x+y*y);
}
int main()
{
Point mp1(1,1),mp2(4,5);
cout<<"len="<<dist(mp1,mp2)<<endl;
return 0;
}
为什么把dist的参数前面的地址符去掉结果变了
求大神指点
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
Point (int x=0,int y=0):x(x),y(y){cout<<"构造函数被调用"<<endl;}
Point (Point &p){cout<<"复制构造函数被调用"<<endl;x=p.x;y=p.y;}
friend double dist(Point p1,Point p2);
private:
int x,y;
};
double dist(Point p1,Point p2)
{
double x=p2.x-p1.x;
double y=p2.y-p1.y;
return sqrt(x*x+y*y);
}
int main()
{
Point mp1(1,1),mp2(4,5);
cout<<"len="<<dist(mp1,mp2)<<endl;
return 0;
}
为什么把dist的参数前面的地址符去掉结果变了
求大神指点 |
|