• <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 閱讀(230) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            97久久精品人人澡人人爽| 久久人人爽人人爽人人片AV不| 香蕉久久一区二区不卡无毒影院| 91精品国产高清久久久久久91| 久久精品女人天堂AV麻| 久久精品国产久精国产果冻传媒 | 69国产成人综合久久精品| 国产精品美女久久久久网| 国内精品久久久久久久影视麻豆| 久久99热这里只有精品66| 久久国产精品99精品国产987| 久久综合久久性久99毛片| 久久亚洲精品中文字幕| 国内精品免费久久影院| 亚洲综合伊人久久大杳蕉| 国产精品成人99久久久久 | 久久久久久毛片免费播放| 久久青青草原亚洲av无码| 久久av无码专区亚洲av桃花岛| 久久综合久久鬼色| 国产精品热久久无码av| 欧美熟妇另类久久久久久不卡| 日本欧美国产精品第一页久久| 热re99久久精品国产99热| 亚洲精品无码久久久久| 中文字幕无码久久久| 99久久99久久| 日韩AV无码久久一区二区| 亚洲午夜精品久久久久久app| 久久无码国产| 久久久久久无码国产精品中文字幕| 2022年国产精品久久久久| 欧美喷潮久久久XXXXx| 亚洲中文字幕无码久久精品1| 久久伊人精品一区二区三区| 亚洲精品国产综合久久一线| 亚洲人成电影网站久久| 久久亚洲中文字幕精品一区| 欧美日韩精品久久久久| 久久久久久久久久久精品尤物| 欧美伊人久久大香线蕉综合|