啪啪拉拉噼里啪啦

          初學者天堂資料匯集

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            16 隨筆 :: 73 文章 :: 16 評論 :: 0 Trackbacks

          構造函數和拷貝構造函數的實例

          #include<iostream.h>

          class Point
          {  public:                                          //共有數據  外部接口
               Point(int xx=0,int yy=0)          //構造函數
                      { 
                          X=xx;
                          Y=yy;
                     }
                Point(Point &P);                      // 拷貝構造函數
                int GetX()
                  { return X;}
                int GetY()
                   { retrun Y;}
           private:
              int X, int Y;            // 私用數據
          };
          // 成員函數的實現

          Point ::Point(Point &P)
          {  X=P.X;
             Y=P.Y;
            cout<<"拷貝構造函數被調用"<<endl;
          }
          void fun1(Point P)
          {  cout<<P.GetX()<<endl;
          }
          void fun2()
          {  Point A(1,2)
              retrun A;

          }

          void main()
          {  Point A(4,5);
             Point B(A);
            cout<<B.GetX()<<endl;
            fun1(B);
          B=fun2();
          cout<<B.GetX()<<endl;
          }

          posted on 2005-04-01 17:56 噼里啪啦的世界 閱讀(108) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 隆子县| 亚东县| 金山区| 甘孜| 绵阳市| 广宁县| 崇文区| 上饶县| 舞钢市| 武功县| 米林县| 昌黎县| 克拉玛依市| 高陵县| 遵义县| 赤水市| 赣州市| 界首市| 隆尧县| 恩平市| 灵丘县| 塔城市| 增城市| 无极县| 大悟县| 积石山| 万安县| 和田市| 沭阳县| 龙州县| 闸北区| 临沭县| 吉隆县| 延边| 长泰县| 安顺市| 马公市| 崇礼县| 莱阳市| 枞阳县| 广饶县|