• <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++實(shí)例研究

            從0開(kāi)始

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              104 隨筆 :: 0 文章 :: 20 評(píng)論 :: 0 Trackbacks
            /*
              Name: Why C++ ?(2)(plus on/off funtion)
              Copyright: 
              Author: elprup
              Date: 08/10/10 09:18
              Description: 
            */
            #include 
            <cstdio>
            #include 
            <cstdlib>
            #include 
            <iostream>
            using namespace std;

            //on/off for c on/off function
            bool on = true;

            int print(const char* s)
            {
                
            extern bool on;
                
            if(on)
                    printf(
            "%s\n", s);
                
            return 0;    
            }

            void badguy()
            {
                
            extern bool on;
                on 
            = false//modify global varity
                return;
            }

            class trace_cpp
            {
            public:
                
            //easy to initial state of class, but c need special attention.
                trace_cpp():m_on(true){}
                
            int print(const char*s)const{if(m_on) printf("%s\n", s); return 0;}
                
            int on(){m_on = truereturn 0;}
                
            int off(){m_on = falsereturn 0;}
            private:
                
            //add class related varity, not see out of class
                bool m_on;
            };

            int main()
            {
                
            //c style trace
                print("Hello from c.");
                
                
            //cpp style trace;
                trace_cpp tc;
                tc.print(
            "Hello from c++");
                
                
            //turn on/off c style trace
                extern bool on;
                on 
            = false;
                print(
            "Wont display from c.");
                on 
            = true;
                print(
            "Will display from c.");
                
            //it looks working fine, but if foo() modify it?
                badguy();
                print(
            "Want to display, but won't from c.");
                
                
            //turn on/off cpp style
                tc.off();
                tc.print(
            "Wont display from cpp.");
                tc.on();
                tc.print(
            "Will display from cpp.");
                
            //so we hardly find a function to modify state of trace cpp
                
                system(
            "PAUSE");
                
            return 0;
            }
            posted on 2010-10-08 09:45 elprup 閱讀(412) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): c++實(shí)例
            人人狠狠综合久久亚洲88| 亚洲欧美精品一区久久中文字幕| 亚洲伊人久久大香线蕉综合图片| 人妻精品久久久久中文字幕69 | 久久免费视频1| 国产99久久久国产精品小说| 久久棈精品久久久久久噜噜| 国产高潮国产高潮久久久91| 合区精品久久久中文字幕一区| 欧美va久久久噜噜噜久久| 国产亚洲成人久久| 精品久久久久久国产| 国产精品成人久久久久久久| 久久人妻少妇嫩草AV蜜桃| 91精品国产91久久| 久久综合九色综合网站| 亚洲性久久久影院| 亚洲精品高清国产一久久| 久久强奷乱码老熟女网站| 久久久WWW成人免费毛片| 国产精品一久久香蕉国产线看| 欧美亚洲另类久久综合婷婷| 久久香蕉国产线看观看99| 人妻丰满AV无码久久不卡| 中文字幕亚洲综合久久菠萝蜜| 午夜不卡888久久| 精品久久久久久亚洲| 久久人人爽人人爽人人AV东京热 | 久久亚洲高清综合| 精品久久久久久久| 亚洲国产成人久久综合一| 欧美黑人又粗又大久久久| 亚洲精品乱码久久久久久自慰 | 久久国产免费| 国内精品久久久久久久久| 国产一区二区精品久久岳| jizzjizz国产精品久久| 久久国产精品久久久| 女人香蕉久久**毛片精品| 久久久久国产精品| 国产午夜精品理论片久久|