• <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++實例
            狠狠色噜噜狠狠狠狠狠色综合久久| 久久精品无码一区二区三区免费| 久久免费看黄a级毛片| av国内精品久久久久影院| 99久久精品国产毛片| 久久国产色av免费看| AA级片免费看视频久久| 国内精品久久久久影院薰衣草| 久久久久久午夜成人影院| 久久久久无码精品国产app| 99蜜桃臀久久久欧美精品网站 | 韩国三级中文字幕hd久久精品| 亚洲综合久久夜AV | 精品视频久久久久| 久久久久人妻精品一区二区三区| 久久精品无码专区免费| 久久96国产精品久久久| 亚洲精品国产字幕久久不卡| 99久久国产亚洲高清观看2024| 日韩人妻无码一区二区三区久久| 久久精品女人天堂AV麻| 久久综合久久久| 久久久精品国产sm调教网站| 久久久久久久精品成人热色戒| 青青青国产成人久久111网站| 久久免费的精品国产V∧| 亚洲中文字幕无码一久久区| 久久久久久久综合狠狠综合| 精品久久久久久| 97超级碰碰碰久久久久| 久久偷看各类wc女厕嘘嘘| 久久综合综合久久综合| 亚洲中文字幕久久精品无码喷水| 国产精品久久婷婷六月丁香| 欧美精品国产综合久久| 一本色道久久综合| 欧美熟妇另类久久久久久不卡 | 久久毛片一区二区| 久久婷婷午色综合夜啪| 国内精品久久久久久久久电影网 | 久久综合九色综合97_久久久|