• <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 閱讀(408) 評論(0)  編輯 收藏 引用 所屬分類: c++實例
            久久综合伊人77777| 99re久久精品国产首页2020| 久久久久亚洲av成人网人人软件| 一本一本久久aa综合精品| 丁香五月网久久综合| 无码人妻少妇久久中文字幕| 久久精品国产亚洲AV香蕉| 久久综合色区| 9久久9久久精品| 久久久国产精华液| 久久久精品人妻无码专区不卡| A狠狠久久蜜臀婷色中文网| 久久久精品国产免大香伊| 欧洲性大片xxxxx久久久| 久久无码av三级| 久久精品国产亚洲AV高清热| 亚洲伊人久久综合影院| 久久99精品久久久久久噜噜 | 久久久久波多野结衣高潮| 久久99精品久久久久久齐齐| 91久久精品91久久性色| 精品综合久久久久久97| 久久国产亚洲精品| 久久综合伊人77777麻豆| 久久精品成人一区二区三区| 亚洲午夜精品久久久久久人妖| 99精品国产在热久久无毒不卡| 精品国产99久久久久久麻豆| 国产精品久久久久久五月尺| 欧美日韩精品久久久久| 亚洲国产成人久久一区久久| 日批日出水久久亚洲精品tv| 热综合一本伊人久久精品| 精品无码久久久久久久动漫| 国产亚洲色婷婷久久99精品91| 99久久人人爽亚洲精品美女| 久久精品国产72国产精福利| 久久久久久无码国产精品中文字幕| 久久久久久A亚洲欧洲AV冫| 久久人人爽人人爽AV片| 亚洲欧洲精品成人久久曰影片|