• <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 閱讀(231) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            91久久精品国产免费直播| 国产精品久久波多野结衣| 中文字幕成人精品久久不卡| 精品久久久久中文字| 亚洲国产一成久久精品国产成人综合 | 人人狠狠综合久久亚洲| 久久久WWW成人免费毛片| 亚洲伊人久久综合中文成人网| 国产成人精品综合久久久| 91精品婷婷国产综合久久| 亚洲va久久久噜噜噜久久男同 | 久久国产乱子精品免费女| 日韩欧美亚洲国产精品字幕久久久| 97久久婷婷五月综合色d啪蜜芽| 国产精品成人久久久久三级午夜电影| 久久中文字幕人妻熟av女| 久久伊人精品青青草原高清| 久久天天躁狠狠躁夜夜躁2O2O | 狠狠色狠狠色综合久久| AA级片免费看视频久久| 国产美女久久精品香蕉69| 久久婷婷五月综合色奶水99啪| 噜噜噜色噜噜噜久久| 久久久久久极精品久久久| 亚洲а∨天堂久久精品9966| 日日狠狠久久偷偷色综合96蜜桃| 久久精品国产第一区二区| 亚洲午夜精品久久久久久app| 三级片免费观看久久| 国产999精品久久久久久| 精品久久久久久无码专区| 国产∨亚洲V天堂无码久久久| 久久国产视屏| 精品久久人人妻人人做精品| 亚洲?V乱码久久精品蜜桃| 久久99久久99精品免视看动漫 | 国产精品美女久久久免费| 久久强奷乱码老熟女网站| 中文字幕乱码人妻无码久久| 国产精品久久永久免费| 久久乐国产综合亚洲精品|