• <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í)例
            久久天天婷婷五月俺也去| 中文字幕无码免费久久| 久久久久久无码Av成人影院| 久久丫精品国产亚洲av| 久久99精品久久久久久水蜜桃| 久久久国产视频| 亚洲AV无码一区东京热久久| 国内精品伊人久久久久影院对白| 亚洲精品tv久久久久| 久久久久久综合一区中文字幕| 亚洲色欲久久久久综合网| 三上悠亚久久精品| 久久亚洲AV无码西西人体| 国产精品美女久久久久AV福利| 久久天天躁狠狠躁夜夜avapp| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲国产精品久久久久久| 久久夜色精品国产网站| 精品久久久久久久中文字幕| 久久人人妻人人爽人人爽| 久久人人爽人人澡人人高潮AV | 曰曰摸天天摸人人看久久久| 亚洲欧美成人久久综合中文网| 久久精品国产精品青草app| 久久精品亚洲一区二区三区浴池| 久久丝袜精品中文字幕| 久久精品女人天堂AV麻| 色综合久久久久| 人妻久久久一区二区三区| 久久人人爽人人爽人人av东京热| 日本亚洲色大成网站WWW久久| 国产精品久久亚洲不卡动漫| 99久久精品日本一区二区免费| 国产精品99精品久久免费| 亚洲国产精品无码久久SM| 狠狠色丁香久久婷婷综合_中 | 久久夜色精品国产亚洲av| 久久福利青草精品资源站| 97久久久精品综合88久久| 国产亚洲欧美成人久久片| 久久久久久a亚洲欧洲aⅴ|