复制构造函数的疑问

最近在B站看C++ 课程,发现复制构造函数调用举例 跟自己的调试不一样。以下是代码。

#include <iostream>
using namespace std;
class Point{
    public:
    Point();
    Point(const Point &obj);
    void getPosition();
    private:
    int x,y;
};
Point::Point(){
    cout<<"Calling Constructor "<<endl;
}
Point::Point(const Point &p){
    x = p.x;
    y = p.y;
    cout<<"Calling Copy Constructor "<<endl;
}
void Point::getPosition(){
    cout<<"x "<<x<<" y "<<y<<endl;
}
void fun1(Point p);
Point fun2();
int main(){
    Point a;
    a.getPosition();
    cout<<"\n"<<endl;

    Point c;
    c.getPosition();
    cout<<"\n"<<endl;

    Point b(a);
    b.getPosition();
    cout<<"\n"<<endl;

    fun1(b);
    cout<<"\n"<<endl;

    b = fun2();
    b.getPosition();
    return 0;
}
void fun1(Point p){
    cout<<"Calling fun1 begin"<<endl;
    p.getPosition();
    cout<<"Calling fun1 end"<<endl;
}
Point fun2(){
    cout<<"Calling fun2 begin"<<endl;
    Point b;
    cout<<"Calling fun2 end"<<endl;
    return b;
}

下边是打印结果

Calling Constructor
x -400344992 y 32766
Calling Constructor
x 0 y 0
Calling Copying Constructor
x -400344992 y 32766
Calling Copying Constructor
Calling fun1 begin
x -400344992 y 32766
Calling fun1 end
Calling fun2 begin
Calling Constructor
Calling fun2 end
x 0 y 0

B站的视频说在调用fun2()的时候也会发生复制,但是结果里并没有发生。
是我弄错了?

另一个疑问就是:Point aPoint c 初始化顺序不一样,x,y的值也不一样?

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 265-英-小作业2 素材 关于最近的热门话题996 我想到李海鹏先生的一段话,他说高投入的工作起码要满足以下四个...
    be337baac8f4阅读 99评论 0 1
  • 06年离开云南来到北京,这么多年依旧执爱着云南的天空,鲜花,美食,那里的人儿。 在北京吃不到正宗的米线,吃不到好吃...
    Demi呆米阅读 154评论 1 1
  • 1、 事情要有轻重缓急,一堆事出现时,列个条目。绝对要尽早办理。早早早 2、做饭能力要比熟知饭店美食的能力重要的多...
    遇见光阴阅读 154评论 0 1
  • 忘了夏天是在哪一天来临,或许是柳絮飞扬的某一个黄昏,也或许是蔷薇花盛开的某一个清晨。 在热辣辣的太阳烘烤着大地的时...
    枕梦vivian阅读 371评论 1 5
  • 从司马懿政变看捭阖时机 司马懿是曹操的中人,其子曹丕,曹丕之一曹睿,曹睿之子曹芳均拜其辅佐。曹芳之时,曹芳年幼,当...
    llpspark阅读 241评论 0 0