• <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
            /*
              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) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            亚洲午夜久久久久久噜噜噜| 婷婷伊人久久大香线蕉AV| 国产精品一区二区久久精品涩爱| 久久久久亚洲AV片无码下载蜜桃| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 999久久久无码国产精品| 狠狠色丁香久久婷婷综合_中| 久久人人爽人人爽人人片AV不| 欧美精品乱码99久久蜜桃| AV无码久久久久不卡蜜桃| 国产精品一区二区久久不卡| 久久九九全国免费| 一本大道久久东京热无码AV| 亚洲中文字幕无码久久精品1| 久久99精品国产麻豆| 久久久久99精品成人片| 无码人妻精品一区二区三区久久| 狠狠色丁香久久婷婷综合五月 | 青青青青久久精品国产| 亚洲国产成人久久综合野外| 丁香色欲久久久久久综合网| 三上悠亚久久精品| 久久九九久精品国产| 无码人妻少妇久久中文字幕蜜桃 | 国产精品狼人久久久久影院| 无码任你躁久久久久久老妇App| 91精品国产综合久久精品| 亚洲国产精品一区二区三区久久| MM131亚洲国产美女久久| 伊人色综合久久天天人守人婷| 久久精品99久久香蕉国产色戒| 久久成人精品| 精品久久久久久亚洲| 成人久久免费网站| 亚洲国产成人久久综合野外| 久久99毛片免费观看不卡| 亚洲国产精品久久久天堂| 亚洲美日韩Av中文字幕无码久久久妻妇 | 亚洲国产欧洲综合997久久| 欧美精品福利视频一区二区三区久久久精品 | 精品国产乱码久久久久软件|