• <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++實(shí)例研究

            從0開(kāi)始

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              104 隨筆 :: 0 文章 :: 20 評(píng)論 :: 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 閱讀(229) 評(píng)論(0)  編輯 收藏 引用 所屬分類: c++實(shí)例
            亚洲国产精品嫩草影院久久| 久久亚洲私人国产精品vA| 91精品免费久久久久久久久| 国产精品欧美亚洲韩国日本久久| 亚洲欧美精品一区久久中文字幕 | 亚洲AV日韩精品久久久久久久| 精品人妻久久久久久888| 久久se精品一区二区影院| 国产精品久久婷婷六月丁香| 久久99国产精品一区二区| 亚洲一区精品伊人久久伊人| 精品久久久久久无码中文字幕一区| 久久av高潮av无码av喷吹| 久久ZYZ资源站无码中文动漫| 久久九色综合九色99伊人| 久久99精品久久只有精品| 一级做a爰片久久毛片毛片| 9191精品国产免费久久| 久久久久高潮毛片免费全部播放| 内射无码专区久久亚洲| 久久99国产精品99久久| 色婷婷久久综合中文久久蜜桃av| 色婷婷噜噜久久国产精品12p | 91久久精品电影| 日韩人妻无码一区二区三区久久| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 精品国产乱码久久久久久呢| 久久精品二区| 99久久精品免费观看国产| 69久久夜色精品国产69| 麻豆一区二区99久久久久| 伊人久久精品无码av一区| 国产精品乱码久久久久久软件| 色婷婷久久综合中文久久一本| 欧美午夜精品久久久久久浪潮| 91久久福利国产成人精品| 88久久精品无码一区二区毛片| 久久精品一区二区国产| .精品久久久麻豆国产精品 | 欧美久久久久久精选9999| 91精品国产高清久久久久久国产嫩草 |