求帮我解释这两段c++输出结果


#include<iostream> 
using namespace std; 
class TPoint{
public:
TPoint(int x,int y){
X=x;
Y=y;
} 
TPoint(TPoint &p);
~TPoint(){
cout <<"Destructor is called\n”;
} 
int getx(){
return X;
}
int gety(){
return Y;
}
private:
    int X,Y;
}; 
TPoint::TPoint(TPoint &p){
X= p.X; 
Y=p.Y;
cout<<"Constructor is called\n";
cout <<"Copy-initialization Constructor is called\n";
}
int main(){
TPoint p1(4,9); 
TPoint p2(p1); 
TPoint p3=p2;
cout <<"p3 = ("<< p3. getx( )<<" ,"<< p3.gety( )<<")\n"; 
return 0;
}                                            


输出结果:


Constructor is called.
Copy-initialization Constructor is called
Copy-initialization Constructor is called
p3 = (4 ,9)
Destructor is called
Destructor is called
Destructor is called

```c++
#include
#include
using namespace std;
class My{
public:
My(double i=0){
x=y=i;
}
My(double i,double j){
x=i;y=j;
}
My(My &m){
x=m.x;
y=m.y;
}
friend double dist(My &a,My &b);
private:
double x,y;
};
double dist(My&a,My&b){
double dx=a.x-b.x;
double dy=a.y-b.y;
return sqrt(dxdx+dy dy);
}
int main(){
My ml,m2(15),m3(13,14);
My m4(m3);
cout<<"The distancel:"<<dist(ml,m3)<<endl;
cout<<"The distance2:"<<dist(m2,m3)<<endl;
cout<<"The distance3:"<<dist(m3,m4)<<endl;
cout<<"The distance4:"<<dist(ml,m2)<<endl;
return 0;
}

输出结果:

```The distancel:19.105
The distance2:2.23607
The distance3:0
The distance4:21.2132

你的输出是错误的。正确的输出应该是:

Constructor is called
Copy-initialization Constructor is called
Constructor is called
Copy-initialization Constructor is called
p3 = (4 ,9)
Destructor is called
Destructor is called
Destructor is called

1-2行是TPoint p2(p1)这句话调用拷贝构造函数时打印的。
3-4行是TPoint p3=p2;这句话调用拷贝构造函数时打印的
p3 = (4 ,9)这句话是cout <<"p3 = ("<< p3. getx( )<<" ,"<< p3.gety( )<<")\n"; 这句话打印的
最后的Destructor is calle三句话是程序结束时,系统自动调用TPoint的析构函数时打印的,用来析构三个TPoint变量

第一个的输出结果你弄错了吧?26、27行是连续的,怎么可能输出会丢掉26,只显示27呢?
TPoint p2(p1);
TPoint p3=p2;
都会调用拷贝构造函数的

第二个结果有什么疑问么?就是算两个点的距离