• <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 閱讀(413) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            久久天天日天天操综合伊人av| 99久久精品国产一区二区| 久久九九兔免费精品6| 97久久国产综合精品女不卡| 久久夜色精品国产噜噜麻豆| 亚洲国产天堂久久综合网站| 久久一本综合| 久久99精品国产自在现线小黄鸭| 国产精品嫩草影院久久| 久久久久亚洲精品天堂| 麻豆av久久av盛宴av| 久久国产成人| 99久久精品国产综合一区 | 久久久久久午夜精品| 伊人热人久久中文字幕| 久久笫一福利免费导航 | 亚洲国产精品热久久| 久久久久高潮综合影院| 久久久久国产一区二区| 久久av免费天堂小草播放| 久久久久亚洲精品天堂| 久久99精品久久久大学生| 韩国三级中文字幕hd久久精品| 久久久亚洲欧洲日产国码二区 | 亚洲色欲久久久综合网| 看全色黄大色大片免费久久久| 国产精品视频久久| 99久久精品毛片免费播放| 国内精品伊人久久久影院| 久久久久婷婷| 国产视频久久| 久久久久婷婷| 四虎国产精品成人免费久久| 无码任你躁久久久久久老妇| 四虎久久影院| 久久精品国产男包| 国产亚洲精久久久久久无码77777| 一本色道久久88综合日韩精品| 久久久久久精品免费看SSS| 久久精品极品盛宴观看| 最新久久免费视频|