c++ 友元类的参数问题

#include
#include
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;
} 图片说明

#include
#include
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的参数前面的地址符去掉结果变了
求大神指点

double dist(Point &p1,Point &p2),该函数的形式参数,相当于是给实参取别名。
double dist(Point p1,Point p2),该函数的形式参数,需要创建局部变量,并将实参的值复制到局部变量中。
Point p1 = mp1,相当于是调用了函数Point (Point &p)。
Point p2 = mp2,也相当于调用了函数Point (Point &p)。
Point (Point &p)该函数叫做拷贝构造函数。

具体可以查看一下C++拷贝构造函数相关知识。

建议好好去补补c++ 的基础知识,引用是基本语法中的...