• <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++實例
            久久精品国产亚洲αv忘忧草| 久久久久久久综合日本亚洲| 亚洲国产精品无码久久青草| 日本久久中文字幕| 色欲久久久天天天综合网精品| 久久精品夜夜夜夜夜久久| 久久久久久免费一区二区三区| 久久精品国产亚洲Aⅴ香蕉| 久久久午夜精品福利内容| 久久丫精品国产亚洲av不卡 | 久久综合精品国产一区二区三区| 亚洲国产成人久久精品99| 久久99精品久久只有精品| 老司机午夜网站国内精品久久久久久久久 | 日本强好片久久久久久AAA| 热99re久久国超精品首页| 久久九九久精品国产免费直播| 精品久久香蕉国产线看观看亚洲| 国产精品久久久久久久app| 欧美精品一本久久男人的天堂| 久久综合视频网| 久久精品三级视频| 99久久免费只有精品国产| 色狠狠久久AV五月综合| 国产一区二区久久久| 久久天天躁狠狠躁夜夜不卡 | 少妇被又大又粗又爽毛片久久黑人| 国产精品99久久99久久久| 中文字幕无码精品亚洲资源网久久| 久久精品国产99久久香蕉| 亚洲国产精品久久久久婷婷老年 | 99久久国产亚洲高清观看2024| 久久久久久久久久久久中文字幕 | 麻豆久久久9性大片| 性做久久久久久免费观看| 久久久久久国产a免费观看不卡 | 精品熟女少妇a∨免费久久| 亚洲午夜久久久久久久久电影网| 日本久久中文字幕| 亚洲乱码日产精品a级毛片久久| 久久亚洲AV永久无码精品|