• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            c++實例研究

            從0開始

              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
              104 隨筆 :: 0 文章 :: 20 評論 :: 0 Trackbacks

             

            #include <cstdlib>
            #include 
            <iostream>
            using namespace std;

            struct bottle
            {
                
            int refCount;
                
            int weight;
                
            int size;
                bottle(
            int w,int sz):refCount(1),weight(w),size(sz){}
                bottle
            * getOwnCopy()
                
            {
                    
            if(refCount==1)
                        
            return this;
                    refCount
            --;
                    
            return new bottle(weight,size);
                }

            private:
                bottle(
            const bottle&);
                bottle
            & operator=(const bottle&);
            }
            ;

            class ProductBottle
            {
            public:
                ProductBottle(
            int w=10,int sz=20):pinst(new bottle(w,sz)){}
                ProductBottle(
            const ProductBottle& other)
                
            {
                    other.pinst
            ->refCount++;
                    pinst 
            = other.pinst;
                }

                ProductBottle
            & operator=(const ProductBottle& rhs)
                
            {
                    rhs.pinst
            ->refCount++;
                    
            if(--pinst->refCount==0)
                        delete pinst;
                    pinst 
            = rhs.pinst;
                    
            return *this;
                }

                
            ~ProductBottle()
                
            {
                    
            if(--pinst->refCount==0)
                        delete pinst;
                }

                
            int AddWater(int waterWeight)
                
            {
                    pinst 
            = pinst->getOwnCopy(); 
                    pinst
            ->weight += waterWeight;
                    
            return 0
                }

                
            int show()
                
            {
                    cout
            <<pinst->weight<<' '<<pinst->size<<' '<<pinst->refCount<<endl;
                }

            private:
                bottle
            * pinst;
            }
            ;

            int main()
            {
                ProductBottle Cola;
                ProductBottle Sprint(Cola);
                ProductBottle Finda(Sprint);
                
            /*****************************/
                Cola.show();
                Sprint.show();
                Finda.show();
                
            /*****************************/
                Cola.AddWater(
            50);
                
            /*****************************/
                Cola.show();
                Sprint.show();
                Finda.show();
                
            /*****************************/    
                system(
            "PAUSE");
                
            return 0;
            }

            posted on 2010-05-10 22:14 elprup 閱讀(238) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            久久99国产一区二区三区| 久久笫一福利免费导航 | 久久久久久久久无码精品亚洲日韩 | 一级做a爱片久久毛片| 久久天天日天天操综合伊人av| 成人综合久久精品色婷婷| 精品久久久久久国产潘金莲| 久久精品国产精品亚洲艾草网美妙 | 精品少妇人妻av无码久久| 四虎影视久久久免费观看| 欧美一区二区三区久久综| 国产精品成人精品久久久| 日韩精品久久久久久久电影蜜臀| 国内精品久久久久久久久电影网| 久久久久亚洲精品日久生情 | 四虎国产精品成人免费久久| 精品久久久久久成人AV| 久久久亚洲AV波多野结衣| 久久九九久精品国产| 久久国产精品99久久久久久老狼| 久久精品国产AV一区二区三区| 99久久国产综合精品成人影院| 囯产极品美女高潮无套久久久| 久久亚洲AV无码西西人体| 久久精品免费观看| 久久精品嫩草影院| 精品国产VA久久久久久久冰 | 久久久久久av无码免费看大片| 久久99精品综合国产首页| 97精品久久天干天天天按摩 | 久久久久99精品成人片| 99久久精品国产一区二区三区| 久久香蕉国产线看观看乱码| 久久99热国产这有精品| 免费观看成人久久网免费观看| 91久久婷婷国产综合精品青草| 久久久一本精品99久久精品66| 亚洲国产美女精品久久久久∴| 亚洲综合日韩久久成人AV| 久久精品国产亚洲av麻豆小说 | 精品久久久久久国产 |