• <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>
            #include 
            <vector>
            using namespace std;

            class trival
            {
            public:
                
            void show(){cout<<e1<<' '<<e2<<' '<<e3<<endl;}
            private:
                
            int e1,e2,e3;
            }
            ;

            void show(trival& t)
            {
                t.show();    
            }


            int main()
            {
                vector
            <trival> tt(5);  
                for_each(tt.begin(),tt.end(),show);
                system(
            "PAUSE");
                
            return 0;
            }

            如果我需要累加三元組的第一號元素
            #include <cstdlib>
            #include 
            <iostream>
            #include 
            <vector>
            using namespace std;

            class trival
            {
            public:
                
            void show(){cout<<e1<<' '<<e2<<' '<<e3<<endl;}
            public:
                
            int e1,e2,e3;
            }
            ;

            void show(trival& t)
            {
                t.show();    
            }


            void inc(trival& t)
            {
                t.e1
            ++;
            }


            int main()
            {
                vector
            <trival> tt(5);  
                for_each(tt.begin(),tt.end(),show);
                for_each(tt.begin(),tt.end(),inc);
                for_each(tt.begin(),tt.end(),show);
                system(
            "PAUSE");
                
            return 0;
            }

            問題出現了,如果我想自定義給三元組的每個元素加n呢?于是。。。
            #include <cstdlib>
            #include 
            <iostream>
            #include 
            <vector>
            using namespace std;

            class trival
            {
            public:
                
            void show(){cout<<e1<<' '<<e2<<' '<<e3<<endl;}
            public:
                
            int e1,e2,e3;
            }
            ;

            void show(trival& t)
            {
                t.show();    
            }


            class add
            {
            public:
                add(
            int ae1=0int ae2=0int ae3=0):adde1(ae1),adde2(ae2),adde3(ae3){}
                
            void operator()(trival& t){t.e1+=adde1; t.e2+=adde2; t.e3+=adde3;}
            private:
                
            int adde1,adde2,adde3;
            }
            ;

            int main()
            {
                vector
            <trival> tt(5);  
                for_each(tt.begin(),tt.end(),show);
                for_each(tt.begin(),tt.end(),add(
            1,2));
                for_each(tt.begin(),tt.end(),show);
                system(
            "PAUSE");
                
            return 0;
            }


            是不是很有意思?
            posted on 2010-05-09 16:56 elprup 閱讀(255) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            久久精品成人影院| 国产精品久久国产精品99盘| 国产精品成人无码久久久久久 | 午夜精品久久久久| 久久久久亚洲av无码专区 | 国产L精品国产亚洲区久久| 无码人妻少妇久久中文字幕| 久久精品国产亚洲AV无码偷窥 | 精品久久久中文字幕人妻| 久久91精品国产91久久户| 久久久精品久久久久影院| 四虎国产精品免费久久久| 亚洲国产精品无码成人片久久| 久久这里只精品国产99热| 国产亚洲精久久久久久无码77777 国产亚洲精品久久久久秋霞 | 久久青青草原国产精品免费| 中文字幕无码精品亚洲资源网久久| 久久99国产精品99久久| 亚洲AV日韩AV永久无码久久| 久久伊人五月天论坛| 亚洲嫩草影院久久精品| 精品无码久久久久久午夜| 国产69精品久久久久9999APGF| 色综合久久天天综线观看| 国产 亚洲 欧美 另类 久久| 丰满少妇高潮惨叫久久久| 亚洲日本va中文字幕久久| 久久久久久久久波多野高潮| 久久经典免费视频| 青青草原综合久久大伊人| 久久受www免费人成_看片中文| 久久精品无码一区二区app| 精品国产一区二区三区久久蜜臀| 人人狠狠综合久久亚洲88| 午夜不卡888久久| 久久久久久久久久久免费精品| 精品久久久久一区二区三区| 久久精品国产亚洲5555| 欧美精品丝袜久久久中文字幕| 亚洲国产精品成人久久蜜臀 | 一本久久久久久久|