• <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++實例
            中文字幕精品无码久久久久久3D日动漫| 久久精品18| 久久精品国产亚洲AV香蕉| 亚洲中文字幕无码久久2017| 久久99久国产麻精品66| 99国产精品久久| 污污内射久久一区二区欧美日韩 | 99久久99这里只有免费的精品| 东京热TOKYO综合久久精品| 久久精品中文字幕第23页| 五月丁香综合激情六月久久| 91久久成人免费| 亚洲国产精品久久电影欧美| 国产精品免费久久久久影院 | 91精品国产91久久久久久蜜臀| 久久狠狠一本精品综合网| 国产精品久久久亚洲| 欧美大战日韩91综合一区婷婷久久青草 | 久久久久综合网久久| 国产精品久久久久久久人人看| 日本精品久久久中文字幕| 国内高清久久久久久| 色婷婷噜噜久久国产精品12p| 99久久99久久精品免费看蜜桃| 久久精品中文字幕一区| 久久本道久久综合伊人| 亚洲国产精品久久久久久| 久久不见久久见免费视频7| 精品国产乱码久久久久久呢| 久久久WWW成人免费毛片| 91精品国产高清久久久久久国产嫩草 | 久久久久人妻一区二区三区vr| 99久久综合国产精品免费| 无码8090精品久久一区| 女同久久| 久久精品久久久久观看99水蜜桃| 要久久爱在线免费观看| 18禁黄久久久AAA片| 久久AV高潮AV无码AV| 亚洲AV日韩精品久久久久久 | 国产精品久久久亚洲|