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

            foobar

              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              6 隨筆 :: 14 文章 :: 0 評(píng)論 :: 0 Trackbacks

            2007年12月3日 #

            Advanced Test in C: The 0x10 Best Questions for C Programmers
            posted @ 2007-12-03 15:12 foobar 閱讀(195) | 評(píng)論 (0)編輯 收藏

            2007年11月23日 #

             

            #include <iostream.h>
            class Base
            {
            public:
            virtual void f(float x){ cout << "Base::f(float) " << x << endl; }
            void g(float x){ cout << "Base::g(float) " << x << endl; }
            void h(float x){ cout << "Base::h(float) " << x << endl; }
            };
            class Derived : public Base
            {
            public:
            virtual void f(float x){ cout << "Derived::f(float) " << x << endl; }
            void g(int x){ cout << "Derived::g(int) " << x << endl; }
            void h(float x){ cout << "Derived::h(float) " << x << endl; }
            };

            void main(void)
            {
            Derived d;
            Base 
            *pb = &d;
            Derived 
            *pd = &d;
            // Good : behavior depends solely on type of the object
            pb->f(3.14f); // Derived::f(float) 3.14
            pd->f(3.14f); // Derived::f(float) 3.14
            // Bad : behavior depends on type of the pointer
            pb->g(3.14f); // Base::g(float) 3.14
            pd->g(3.14f); // Derived::g(int) 3 (surprise!)
            // Bad : behavior depends on type of the pointer
            pb->h(3.14f); // Base::h(float) 3.14 (surprise!)
            pd->h(3.14f); // Derived::h(float) 3.14
            }

            class Base
            {
            public:
            void f(int x);
            };
            class Derived : public Base
            {
            public:
            void f(char *str);
            };
            void Test(void)
            {
            Derived 
            *pd = new Derived;
            pd
            ->f(10); // error
            //why?            
            just imagine multiple inheritance
            }
            posted @ 2007-11-23 20:44 foobar 閱讀(330) | 評(píng)論 (0)編輯 收藏

             

             1 # include <iostream.h>
             2 void output( int x); // 函數(shù)聲明
             3 void output( float x); // 函數(shù)聲明
             4 void output( int x)
             5 {
             6 cout << " output int " << x << endl ;
             7 }
             8 void output( float x)
             9 {
            10 cout << " output float " << x << endl ;
            11 }
            12 void main(void)
            13 {
            14 int x = 1;
            15 float y = 1.0;
            16 output(x); // output int 1
            17 output(y); // output float 1
            18 output(1); // output int 1
            19 // output(0.5); // error! ambiguous call, 因?yàn)樽詣?dòng)類型轉(zhuǎn)換
            20 output(int(0.5)); // output int 0
            21 output(float(0.5)); // output float 0.5
            22 }
            posted @ 2007-11-23 20:35 foobar 閱讀(463) | 評(píng)論 (0)編輯 收藏

            void Func(char a[100])
            {
            cout<< sizeof(a) << endl; // 4 字節(jié)而不是100 字節(jié)
            }
            posted @ 2007-11-23 20:22 foobar 閱讀(309) | 評(píng)論 (0)編輯 收藏

            2007年11月15日 #

            int atexit ( void ( * function ) (void) );               <cstdlib>

             The function pointed by the function pointer argument is called when the program terminates normally.

            If more than one atexit function has been specified by different calls to this function, they are all executed in reverse order as a stack, i.e. the last function specified is the first to be executed at exit.

            One single function can be registered to be executed at exit more than once.

            C++ implementations are required to support the registration of at least 32 atexit functions.

            Parameters

            function
            Function to be called. The function has to return no value and accept no arguments.

            Return Value

            A zero value is returned if the function was successfully registered, or a non-zero value if it failed.

            Example

            /* atexit example */
                        #include <stdio.h>
                        #include <stdlib.h>
                        void fnExit1 (void)
                        {
                        puts ("Exit function 1.");
                        }
                        void fnExit2 (void)
                        {
                        puts ("Exit function 2.");
                        }
                        int main ()
                        {
                        atexit (fnExit1);
                        atexit (fnExit2);
                        puts ("Main function.");
                        return 0;
                        }
                        

            Output:
            
                        Main function.
            Exit function 2.
            Exit function 1.

            posted @ 2007-11-15 23:47 foobar 閱讀(472) | 評(píng)論 (0)編輯 收藏

            2007年6月4日 #

            Initializer lists

            In C++, it is the order of the class inheritance and of the member variables that determine the initialization order, not the order of an initializer list:



            #include 
            <iostream>

            class CSomeClass
            {
            public:
            CSomeClass(
            int n)
            {
            std::cout 
            << "CSomeClass constructor with value ";
            std::cout 
            << n << std::endl;
            }

            }
            ;

            class CSomeOtherClass
            {
            public:
            CSomeOtherClass() 
            //In this example, despite the list order,
            : obj2(2), obj1(1//obj1 will be initialized before obj2.
            {
            //Do nothing.
            }

            private:
            CSomeClass obj1;
            CSomeClass obj2;
            }
            ;

            int main(void)
            {
            CSomeOtherClass obj;
            return 0;
            }

            posted @ 2007-06-04 11:11 foobar 閱讀(210) | 評(píng)論 (0)編輯 收藏

            僅列出標(biāo)題  
            精品久久香蕉国产线看观看亚洲| 亚洲乱亚洲乱淫久久| 热久久国产精品| 久久国产精品99精品国产| 亚洲午夜无码久久久久| 欧美日韩久久中文字幕| 伊人久久大香线蕉成人| 亚洲伊人久久成综合人影院| 久久激情五月丁香伊人| 欧美激情精品久久久久久久九九九| 国产精品日韩欧美久久综合| 久久久久综合国产欧美一区二区| 一本一道久久精品综合| 久久久精品波多野结衣| 久久综合狠狠综合久久97色| 亚洲欧洲精品成人久久曰影片| 久久91精品国产91| 久久青青草原亚洲av无码app| 精品久久久久久无码专区不卡| 国产精品福利一区二区久久| 国产精品美女久久久久AV福利 | 久久高潮一级毛片免费| 精品久久人人做人人爽综合| 香蕉99久久国产综合精品宅男自| 精品综合久久久久久97| 久久国产精品99国产精| Xx性欧美肥妇精品久久久久久| 久久久受www免费人成| 久久天天躁狠狠躁夜夜不卡| 99久久99这里只有免费的精品| 久久久久亚洲AV无码专区桃色| 久久精品国产精品亚洲精品| 久久狠狠色狠狠色综合| 亚洲伊人久久综合中文成人网| 波多野结衣中文字幕久久| 亚洲?V乱码久久精品蜜桃 | 无码专区久久综合久中文字幕 | 亚洲精品无码久久久久AV麻豆| 久久亚洲精品人成综合网| 久久天天日天天操综合伊人av| 久久亚洲精品国产精品|