• <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>
            隨筆-145  評(píng)論-173  文章-70  trackbacks-0
            首先來看看下面這段代碼:
            #include <iostream>
            using namespace std;
            class test
            {
            public:
                test(int a,float b)
                {
                    x =  a;
                    y = b;
                }
                void show()
                {
                    cout << "x = " << x << endl
                        << "y = " << y << endl;
                }
            private:
                int x ;
                float y;
            };
            void main()
            {
                test b(1,3.2);
                b.show();
            }
            完全沒有問題,自己定義了一個(gè)構(gòu)造函數(shù),而不是系統(tǒng)默認(rèn)的構(gòu)造函數(shù),這樣就不會(huì)出錯(cuò)了!!
            然后看看下面的這段代碼:
            #include <iostream>
            using namespace std;
            class test
            {
            public:
                void show()
                {
                    cout << "x = " << x << endl
                        << "y = " << y << endl;
                }
            private:
                int x;
                double y;
            };
            void main()
            {
                test b(1,3.2);
                b.show();
            }
            然后就會(huì)出錯(cuò),為什么,因?yàn)槟J(rèn)的構(gòu)造函數(shù)是沒有形參,所以你傳遞進(jìn)去的兩個(gè)形參就會(huì)報(bào)錯(cuò)!更不可能把你的那兩個(gè)參數(shù)賦值給它的private內(nèi)容中的形參。
            還可以定義一個(gè)函數(shù)專門進(jìn)行賦值化或者初始化,這樣就相當(dāng)于一個(gè)構(gòu)造函數(shù),可是實(shí)現(xiàn)起來的話就要顯示的調(diào)用set函數(shù)。
            class test
            {
            public:
                void set(int a,float b)
                {
                     x = a;
                     y = b;
                }
                void show()
                {
                     cout << "x = " << x << endl
                        << "y = " << y << endl;
                }
            private:
                int x;
                float y;
            };

            void main()
            {
                test b;
                b.set(1,3.4);
                b.show();
            }
            posted on 2009-11-27 21:42 deercoder 閱讀(492) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C/C++
            久久精品国产99久久久古代| 久久久久婷婷| 久久精品国产精品亚洲毛片| 久久国产亚洲高清观看| 久久不射电影网| 国产精品久久久久久五月尺| 久久久久人妻精品一区二区三区| 一级做a爰片久久毛片人呢| 青青热久久国产久精品 | 老司机午夜网站国内精品久久久久久久久| 精品久久久久久久久久中文字幕| 狠狠综合久久综合88亚洲 | 91精品国产高清久久久久久io| 天天爽天天爽天天片a久久网| 手机看片久久高清国产日韩 | 久久九九青青国产精品| 欧美久久亚洲精品| www.久久热| 久久亚洲精品国产精品婷婷| 久久夜色tv网站| 亚洲国产精品无码久久久秋霞2| 国内精品久久久久久久久| 色欲久久久天天天综合网| 久久久久国产一区二区三区| 久久ZYZ资源站无码中文动漫| 亚洲综合久久久| 久久久久久久综合日本| 午夜不卡888久久| 久久综合给久久狠狠97色| 人人妻久久人人澡人人爽人人精品 | 国产99久久九九精品无码| 久久青青草原亚洲av无码app| 一级a性色生活片久久无| 久久久久国产一区二区| 久久电影网| 99久久精品九九亚洲精品| 国产一区二区三区久久精品| 久久这里只有精品18| 久久夜色精品国产噜噜噜亚洲AV| 欧美精品九九99久久在观看| 日韩久久久久中文字幕人妻|