• <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í)例
            久久九九兔免费精品6| 精品一区二区久久| 亚洲精品高清国产一线久久| 久久久精品人妻一区二区三区蜜桃| 久久青青草原亚洲av无码app| 蜜桃麻豆www久久| 2020久久精品亚洲热综合一本| 99久久综合狠狠综合久久止| 欧洲国产伦久久久久久久| 亚洲精品无码久久久久sm| 日本精品久久久久中文字幕| 久久精品国产免费观看三人同眠| 精品久久久久久久久中文字幕| 久久久久久久波多野结衣高潮| 天天综合久久久网| 久久精品麻豆日日躁夜夜躁| 三级片免费观看久久| 成人精品一区二区久久| 99久久精品费精品国产一区二区 | 伊人久久精品无码av一区| 久久婷婷国产麻豆91天堂| 久久亚洲精品中文字幕| 精品国产乱码久久久久软件| 成人精品一区二区久久久| 好久久免费视频高清| 日韩AV无码久久一区二区| 亚洲狠狠婷婷综合久久久久| 7777精品伊人久久久大香线蕉| 久久国产精品免费| 久久婷婷五月综合成人D啪| 久久99精品久久久久久9蜜桃| 久久久精品一区二区三区| 精品久久久久久久| 99久久免费只有精品国产| 欧美亚洲另类久久综合| 亚洲综合婷婷久久| 国产亚洲美女精品久久久| 久久久久久久国产免费看| 欧美伊人久久大香线蕉综合69| 久久亚洲av无码精品浪潮| 色婷婷噜噜久久国产精品12p|