• <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 閱讀(238) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            久久99国产综合精品免费| 人妻少妇精品久久| 久久大香香蕉国产| 国产精品久久久天天影视| 国产精品久久久天天影视香蕉 | 久久天堂AV综合合色蜜桃网 | 一本一本久久aa综合精品 | 热99RE久久精品这里都是精品免费 | 久久婷婷五月综合97色直播| 日韩av无码久久精品免费| 狠狠久久综合| 精品久久久久香蕉网| 久久精品极品盛宴观看| 品成人欧美大片久久国产欧美| 久久精品人妻中文系列| 久久久这里有精品中文字幕| 国产亚洲美女精品久久久久狼| 国产69精品久久久久久人妻精品| 99久久精品无码一区二区毛片| 午夜久久久久久禁播电影| 久久亚洲中文字幕精品一区| 国产激情久久久久影院老熟女| 久久精品亚洲中文字幕无码麻豆| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久久一本精品99久久精品66| 色婷婷久久久SWAG精品| 久久精品一区二区影院| 久久99国产一区二区三区| 国产成人香蕉久久久久| 办公室久久精品| 国产成人久久777777| 国内精品久久久久久久影视麻豆| 国内精品久久久久影院网站| 久久国产精品波多野结衣AV| 国产精品va久久久久久久| 国产精品久久久久久久久久免费| 精品视频久久久久| 亚洲国产高清精品线久久 | 亚洲国产精品婷婷久久| 久久激情五月丁香伊人| 色偷偷88欧美精品久久久|