阅读该程序,给出程序的输出结果。 #include <iostream.h> class Point { public:     Point(int i,int j)     {         X=i;         Y=j;     }     Point(Point &rp);     ~Point()     {         cout<<"Destructor called.n";     }     int Xcood()     {         return X;     }     int Ycood()     {         return Y;     } private:     int X,Y; }; Point::Point(Point &rp) {     X=rp.X;     Y=rp.Y;     cout<<"Copy Constructor called.n"; } void main() {     Point p1(6,9);     Point p2(p1);     Point p3=p2,p4(0,0);     p4=p1;     cout<<"p3=("<<p3.Xcood()<<‘,'<<p3.Ycood()<<")n";     cout<<"p4=("<<p4.Xcood()<<‘,'<<p4.Ycood()<<")n"; }-笔试面试资料

这是qklbishe.com第4999 篇笔试面试资料
提供答案分析,通过本文《阅读该程序,给出程序的输出结果。 #include <iostream.h> class Point { public:     Point(int i,int j)     {         X=i;         Y=j;     }     Point(Point &rp);     ~Point()     {         cout<<"Destructor called.n";     }     int Xcood()     {         return X;     }     int Ycood()     {         return Y;     } private:     int X,Y; }; Point::Point(Point &rp) {     X=rp.X;     Y=rp.Y;     cout<<"Copy Constructor called.n"; } void main() {     Point p1(6,9);     Point p2(p1);     Point p3=p2,p4(0,0);     p4=p1;     cout<<"p3=("<<p3.Xcood()<<‘,'<<p3.Ycood()<<")n";     cout<<"p4=("<<p4.Xcood()<<‘,'<<p4.Ycood()<<")n"; }-笔试面试资料》可以理解其中的代码原理,这是一篇很好的求职学习资料
本站提供程序员计算机面试经验学习,笔试经验,包括字节跳动/头条,腾讯,阿里,美团,滴滴出行,网易,百度,京东,小米,华为,微软等互联网大厂真题学习背诵。

答案:

阅读该程序,给出程序的输出结果。

#include <iostream.h>

class Point

{

public:

    Point(int i,int j)

    {

        X=i;

        Y=j;

    }

    Point(Point &rp);

    ~Point()

    {

        cout<<"Destructor called.n";

    }

    int Xcood()

    {

        return X;

    }

    int Ycood()

    {

        return Y;

    }

private:

    int X,Y;

};

Point::Point(Point &rp)

{

    X=rp.X;

    Y=rp.Y;

    cout<<"Copy Constructor called.n";

}

void main()

{

    Point p1(6,9);

    Point p2(p1);

    Point p3=p2,p4(0,0);

    p4=p1;

    cout<<"p3=("<<p3.Xcood()<<‘,'<<p3.Ycood()<<")n";

    cout<<"p4=("<<p4.Xcood()<<‘,'<<p4.Ycood()<<")n";

}

阅读该程序,给出程序的输出结果。      #include &lt;iostream.h&gt;      class Point      {      public:           Point(int i,int j)           {               X=i;              Y=j;           }           Point(Point &amp;rp);          ~Point()           {               cout&lt;&lt;&quot;Destructor called.n&quot;;           }           int Xcood()           {               return X;           }           int Ycood()          {               return Y;           }      private:           int X,Y;      };      Point::Point(Point &amp;rp)      {           X=rp.X;           Y=rp.Y;           cout&lt;&lt;&quot;Copy Constructor called.n&quot;;      }      void main()      {           Point p1(6,9);           Point p2(p1);           Point p3=p2,p4(0,0);           p4=p1;           cout&lt;&lt;&quot;p3=(&quot;&lt;&lt;p3.Xcood()&lt;&lt;','&lt;&lt;p3.Ycood()&lt;&lt;&quot;)n&quot;;           cout&lt;&lt;&quot;p4=(&quot;&lt;&lt;p4.Xcood()&lt;&lt;','&lt;&lt;p4.Ycood()&lt;&lt;&quot;)n&quot;;   } 区块链毕设学生286918393号
Copy Constructor called.
Copy Constructor called.
p3=(6,9)
p4=(6,9)
Destructor called.
Destructor called.
Destructor called.

Destructor called.
复制构造函数的调用有2种方法:
1. 类名  对象1(对象2);
2. 类名  对象1 = 对象2;
都会调用复制构造函数

今天 19:07:29 回复(0)

文章部分来自互联网,侵权联系删除
www.qklbishe.com

区块链毕设网(www.qklbishe.com)全网最靠谱的原创区块链毕设代做网站
部分资料来自网络,侵权联系删除!
资源收费仅为搬运整理打赏费用,用户自愿支付 !
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台 » 阅读该程序,给出程序的输出结果。 #include <iostream.h> class Point { public:     Point(int i,int j)     {         X=i;         Y=j;     }     Point(Point &rp);     ~Point()     {         cout<<"Destructor called.n";     }     int Xcood()     {         return X;     }     int Ycood()     {         return Y;     } private:     int X,Y; }; Point::Point(Point &rp) {     X=rp.X;     Y=rp.Y;     cout<<"Copy Constructor called.n"; } void main() {     Point p1(6,9);     Point p2(p1);     Point p3=p2,p4(0,0);     p4=p1;     cout<<"p3=("<<p3.Xcood()<<‘,'<<p3.Ycood()<<")n";     cout<<"p4=("<<p4.Xcood()<<‘,'<<p4.Ycood()<<")n"; }-笔试面试资料

提供最优质的资源集合

立即查看 了解详情