• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              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 閱讀(228) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            天天综合久久一二三区| 色综合久久无码中文字幕| 久久国产乱子伦精品免费强| 99久久99这里只有免费的精品| 99久久精品毛片免费播放| 久久精品男人影院| 久久这里的只有是精品23| 色欲综合久久中文字幕网| 久久久青草青青亚洲国产免观| 亚洲精品久久久www| 精品午夜久久福利大片| 麻豆久久久9性大片| 7国产欧美日韩综合天堂中文久久久久| 人人狠狠综合久久亚洲高清| 无码精品久久久天天影视| 久久男人中文字幕资源站| 少妇久久久久久久久久| 久久久久黑人强伦姧人妻| 亚洲精品乱码久久久久久蜜桃不卡 | 久久亚洲2019中文字幕| 伊人久久大香线蕉av不变影院| 91精品国产综合久久香蕉 | 久久青青草原精品影院| 亚洲国产欧洲综合997久久| 久久se精品一区二区影院| 欧美久久综合性欧美| 国内精品久久久久伊人av| 一本一道久久综合狠狠老 | 7777久久久国产精品消防器材| 久久99精品久久久久久齐齐| 久久国产亚洲精品麻豆| 久久99国产精品久久99果冻传媒| 亚洲综合熟女久久久30p| 久久久久亚洲AV无码专区首JN| 一本久久精品一区二区| 久久综合色区| 国内精品九九久久精品| 久久精品国产日本波多野结衣| 久久精品极品盛宴观看| 久久热这里只有精品在线观看| 香蕉久久夜色精品国产2020 |