• <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++實例
            无遮挡粉嫩小泬久久久久久久| .精品久久久麻豆国产精品| 精品久久久久中文字| 国产精品永久久久久久久久久 | 久久久一本精品99久久精品88| 久久午夜伦鲁片免费无码| 99久久国产热无码精品免费久久久久| 久久国产精品免费| 伊人久久精品无码二区麻豆| 日本一区精品久久久久影院| 2021国产精品久久精品| 久久99热精品| 亚洲欧洲日产国码无码久久99| 久久福利青草精品资源站免费| 久久久久亚洲AV成人网人人网站 | 久久久久九九精品影院| 亚洲国产精品无码成人片久久| 国产午夜电影久久| 久久久久久免费一区二区三区 | 91精品婷婷国产综合久久| 热99RE久久精品这里都是精品免费| 国产精品免费福利久久| 超级97碰碰碰碰久久久久最新 | 久久久久久精品无码人妻| 久久99久久无码毛片一区二区| 久久久久久久人妻无码中文字幕爆| 久久精品一区二区影院 | 人妻无码中文久久久久专区| 欧美无乱码久久久免费午夜一区二区三区中文字幕| 亚洲精品乱码久久久久久| 综合久久一区二区三区| AAA级久久久精品无码区| 久久久久中文字幕| 久久九九亚洲精品| 国产成人无码精品久久久久免费| 国产精品国色综合久久| 久久国产色AV免费观看| 国产精品女同久久久久电影院 | 99re久久精品国产首页2020| 三上悠亚久久精品| 久久亚洲国产成人精品性色|