• <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開始

              C++博客 :: 首頁 :: 新隨筆 :: 聯(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 閱讀(413) 評(píng)論(0)  編輯 收藏 引用 所屬分類: c++實(shí)例
            国产精品久久久久久久久| 久久亚洲电影| 久久久久免费看成人影片| 国产精品久久成人影院| 激情五月综合综合久久69| 亚洲人成网站999久久久综合| 久久久久亚洲国产| 国产精品久久久久久福利69堂| 久久成人18免费网站| 久久精品无码一区二区WWW| 久久亚洲高清观看| 99久久夜色精品国产网站| 久久亚洲高清观看| 久久99精品国产麻豆宅宅| 欧美亚洲另类久久综合| 一本色道久久HEZYO无码| 国产叼嘿久久精品久久| 亚洲国产一成人久久精品| 久久久久久噜噜精品免费直播| 亚洲精品无码久久千人斩| 亚洲国产精品综合久久网络 | 国产精品毛片久久久久久久| 精品熟女少妇aⅴ免费久久| 久久久久人妻精品一区| 久久久久久精品免费看SSS| 日韩久久无码免费毛片软件| 久久国产精品久久精品国产| 亚洲AV无码久久精品狠狠爱浪潮| 亚洲国产成人久久一区WWW| 国内精品久久久久久久coent| 精品国产一区二区三区久久| 色综合久久综合中文综合网| 久久成人国产精品免费软件| 一级做a爰片久久毛片毛片| 国产免费久久精品99久久| 99久久国产热无码精品免费久久久久| 亚洲欧美伊人久久综合一区二区| 99久久夜色精品国产网站| 欧美日韩精品久久久免费观看| 2021国产精品午夜久久| 精品久久亚洲中文无码|