• <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++實例
            伊人色综合久久天天人手人婷| 粉嫩小泬无遮挡久久久久久| 国产国产成人精品久久| 亚洲日本va中文字幕久久| 性做久久久久久久久久久| 久久精品国产精品亚洲艾草网美妙| 一本一道久久精品综合| 狠狠狠色丁香婷婷综合久久五月| 午夜精品久久久久久久久| 五月丁香综合激情六月久久| 久久亚洲中文字幕精品有坂深雪| 久久人人爽人人人人爽AV | 久久久精品日本一区二区三区| 青青国产成人久久91网| 国产精品伦理久久久久久| AA级片免费看视频久久| 久久综合狠狠综合久久97色| 99久久免费国产精品特黄| 无码超乳爆乳中文字幕久久 | 久久九九久精品国产免费直播| 久久e热在这里只有国产中文精品99| 久久久久黑人强伦姧人妻| 久久亚洲国产最新网站| 无码超乳爆乳中文字幕久久 | 久久久亚洲欧洲日产国码二区| 中文字幕乱码久久午夜| 日本强好片久久久久久AAA| 久久综合丝袜日本网| 激情五月综合综合久久69| 久久久久青草线蕉综合超碰| 99久久久国产精品免费无卡顿| 久久久精品久久久久久| 无码久久精品国产亚洲Av影片| 国产三级观看久久| 中文字幕无码免费久久| 岛国搬运www久久| 久久国产精品成人影院| 久久亚洲高清综合| 久久99国产亚洲高清观看首页| 婷婷久久综合九色综合绿巨人| 久久人人爽爽爽人久久久|