• <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++實例
            a高清免费毛片久久| 久久九九免费高清视频| 久久人人爽人人爽人人片AV麻烦| 欧美久久久久久午夜精品| 手机看片久久高清国产日韩| 欧美精品国产综合久久| 99久久人妻无码精品系列蜜桃| 久久久久久综合一区中文字幕| 久久久久这里只有精品| 久久久久久国产精品美女 | 色婷婷综合久久久久中文一区二区| 亚洲AV无码久久精品成人| 91麻精品国产91久久久久| 欧洲精品久久久av无码电影| 久久www免费人成精品香蕉| 久久夜色精品国产网站| 少妇无套内谢久久久久| 久久精品国产只有精品66| 久久国产精品99精品国产| 欧美亚洲国产精品久久高清 | 久久九九兔免费精品6| 爱做久久久久久| 国产精品一久久香蕉国产线看观看| 日本欧美国产精品第一页久久| 久久精品国产免费| 久久久久久久亚洲Av无码| 久久99久国产麻精品66| 亚洲人成无码网站久久99热国产| 久久综合狠狠综合久久激情 | 人妻少妇久久中文字幕一区二区| 中文字幕精品久久久久人妻| 久久久久女教师免费一区| 久久国产综合精品五月天| 欧美日韩中文字幕久久伊人| 久久99国产精品久久久| 久久99中文字幕久久| 中文字幕亚洲综合久久2| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久99热这里只有精品国产 | 性高湖久久久久久久久AAAAA| 青青国产成人久久91网|