• <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++實例
            国产亚洲精久久久久久无码77777| 99久久成人18免费网站| 久久久久免费精品国产| 久久99热这里只有精品66| 亚洲AV无码久久精品成人| 久久精品国产久精国产思思| 国产V亚洲V天堂无码久久久| 久久天天躁狠狠躁夜夜2020老熟妇 | 午夜福利91久久福利| 伊人色综合久久天天人手人婷| 狠狠88综合久久久久综合网 | 亚洲成色WWW久久网站| 狠狠狠色丁香婷婷综合久久五月| 精品无码久久久久久久动漫 | 久久精品成人免费看| 婷婷国产天堂久久综合五月| 久久99精品国产一区二区三区| 欧美日韩精品久久久免费观看| AV色综合久久天堂AV色综合在| 久久精品国产国产精品四凭| 97久久香蕉国产线看观看| 内射无码专区久久亚洲| 国内精品久久人妻互换| 久久99九九国产免费看小说| 亚洲午夜久久影院| 国产精品久久国产精麻豆99网站 | 97久久精品无码一区二区| 狠狠色丁香久久婷婷综合_中| 色综合久久中文综合网| 久久人人爽人人爽人人片av高请| 性做久久久久久免费观看| 亚洲乱亚洲乱淫久久| 99久久国产综合精品麻豆| 久久久久久夜精品精品免费啦 | 久久午夜无码鲁丝片秋霞| 久久最新免费视频| 三级韩国一区久久二区综合| 久久久久国产| 久久人搡人人玩人妻精品首页 | 97精品国产97久久久久久免费| 国产精品美女久久久m|