• <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++實例
            久久久久国产一区二区三区| 久久久久亚洲AV片无码下载蜜桃| 99久久精品国产综合一区| 久久99精品九九九久久婷婷| 亚洲国产精品嫩草影院久久| 久久久久亚洲AV无码永不| 久久久综合香蕉尹人综合网| 色狠狠久久AV五月综合| 久久激情亚洲精品无码?V| 亚洲精品乱码久久久久久久久久久久 | 久久精品中文字幕久久| 久久久精品波多野结衣| 久久精品蜜芽亚洲国产AV| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久综合噜噜激激的五月天| 久久久久久久国产免费看| 97久久天天综合色天天综合色hd| 精品久久久久久久国产潘金莲 | 一本久久久久久久| 无码人妻久久一区二区三区免费| 久久久精品无码专区不卡| 人人狠狠综合久久亚洲婷婷| 久久久久久久久久久久中文字幕| 亚洲国产日韩欧美综合久久| 精品国产综合区久久久久久| 久久国产成人精品麻豆| 久久精品无码午夜福利理论片| 亚洲Av无码国产情品久久| 久久综合九色综合久99| 国内精品久久久久久野外| 久久无码人妻一区二区三区午夜 | 伊人热热久久原色播放www| 久久久久久久久久免免费精品| 国产真实乱对白精彩久久| 精品乱码久久久久久夜夜嗨| 国产精品免费久久久久久久久| 国产三级精品久久| 久久精品成人免费国产片小草 | 欧美日韩精品久久久免费观看| 无夜精品久久久久久| 麻豆久久久9性大片|