结果为什么会出现三个中文复制构造函数,我明明一次也没调用构造函数啊


#include <iostream>
using namespace std;
class Piont {//Piont类的定义
public://外部借口
    Piont(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;
    }
    Piont(Piont& p);//复制构造函数
    int getX() {
        return x;
    }
    int getY() {
        return y;
    }
private://私有数据
    int x, y;


};
Piont::Piont(Piont& p) {
    x = p.x;
    y = p.y;
    cout << "复制构造函数" << endl;

}
//形参为Piont类对象的函数
void fun1(Piont p) {
    cout << p.getX() << endl;
}
//返回值为Piont类对象的函数
Piont fun2() {
    Piont a(1, 2);
    return a;
}

int main()
{
    Piont a(4, 5);
    Piont b = a;
    cout << b.getX() << endl;
    fun1(b);
    b = fun2();
    cout << b.getX() << endl;
    return 0;






}


![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/144551179746134.png "#left")



#include <iostream>
using namespace std;
class Piont {//Piont类的定义
public://外部借口
    Piont(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;
    }
    Piont(Piont& p);//复制构造函数
    int getX() {
        return x;
    }
    int getY() {
        return y;
    }
private://私有数据
    int x, y;
 
 
};
Piont::Piont(Piont& p) {
    x = p.x;
    y = p.y;
    cout << "复制构造函数" << endl;
 
}
//形参为Piont类对象的函数
void fun1(Piont p) {
    cout << p.getX() << endl;
}
//返回值为Piont类对象的函数
Piont fun2() {
    Piont a(1, 2);
    return a;
}
 
int main()
{
    Piont a(4, 5);
    Piont b = a;//第一次调用复制构造
    cout << b.getX() << endl;
    fun1(b);//第二次调用复制构造,因为传参
    b = fun2();//第三次调用复制构造,因为要构造一个临时的返回值,然后再用operator=把这个返回值赋值给b
    cout << b.getX() << endl;
    return 0;
 
 
 
 
 
 

构造函数是你在new实例的时候自动调用的,你不能显式的调用构造函数