• <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++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              117 Posts :: 2 Stories :: 61 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(8)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

             

                  structC語(yǔ)言的概念,在標(biāo)準(zhǔn)C中,標(biāo)準(zhǔn)C中是不允許在結(jié)構(gòu)中聲明函數(shù)的,而在C++的類中是可以聲明函數(shù)的。

                  但是在C++structclass意義一樣,唯一不同就是struct里面默認(rèn)的訪問(wèn)控制是publicclass中默認(rèn)的訪問(wèn)控制是private。在C++struct中也可以構(gòu)造函數(shù)、析構(gòu)函數(shù)、它們之間也可以繼承

                  下面的代碼演示了struct繼承的例子:

            #include<iostream.h>
            /*******************************************************/
            /* 動(dòng)物基類
            /******************************************************
            */

            enum BREED{GOLDEN,CAING,DANDIE,SHETLAND,DOBERMAN,LAB};
            struct Animal
            {
            public:
                Animal():m_nAge(
            2),m_nWeight(20){}
                
            ~Animal(){}
            //操作
            public:
                
            int GetAge() const{return m_nAge;}//get the age of the animal
                void SetAge(int nAge){m_nAge=nAge;}//set the age of the animal
                int GetWeight()const{return m_nWeight;}//get the wight of the animal
                void SetWeight(int nWeight){m_nWeight=nWeight;}//set the weight of the animal
            //屬性
            protected:
                
            int m_nAge;
                
            int m_nWeight;
            }
            ;
            /*******************************************************/
            /*
            /******************************************************
            */

            struct Cat:public Animal
            {
            public:
                Cat():m_Breed(GOLDEN)
            {}
                
            ~Cat(){}
            public:
                BREED GetBreed()
                
            {
                    
            return m_Breed;
                }

                
            void SetBreed(BREED breed)
                
            {
                    m_Breed
            =breed;
                }

            private:
                BREED m_Breed;
            }
            ;
            /*******************************************************/
            /* 主函數(shù)
            /******************************************************
            */

            int main()
            {
                Cat cat;
                
            int nAge;
                
            int nWeight;
                BREED breed;
                cat.SetAge(
            10);
                cat.SetWeight(
            100);
                cat.SetBreed(GOLDEN);

                nAge
            =cat.GetAge();
                nWeight
            =cat.GetWeight();
                breed
            =cat.GetBreed();

                cout
            <<"Age = "<<nAge<<endl;
                cout
            <<"Weight = "<<nWeight<<endl;
                cout
            <<"BREED = "<<breed<<endl;
                
            return 0;
            }

            代碼的輸出為:


            想要獲得更多內(nèi)容,可點(diǎn)擊:《Visuanl C++代碼參考與技巧大全》學(xué)習(xí)筆記——索引隨筆
            国产A级毛片久久久精品毛片| 久久国产精品99精品国产| 国产一区二区精品久久凹凸| 国产精品免费久久久久久久久 | 久久天天躁狠狠躁夜夜2020| 中文字幕无码久久人妻| 91久久精品91久久性色| 日韩AV毛片精品久久久| 国产精品久久毛片完整版| 蜜臀久久99精品久久久久久| 精品国产VA久久久久久久冰| 久久久久国产| 精品久久久久久无码专区不卡| 国产一区二区精品久久岳| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 久久无码精品一区二区三区| 久久综合给合久久狠狠狠97色69| 国产成人精品久久亚洲| 无码人妻久久一区二区三区| 青春久久| 久久精品国产一区二区三区| 国内精品久久人妻互换| 伊人久久五月天| 伊人色综合久久天天人守人婷 | 国产精品美女久久久久av爽| 久久久老熟女一区二区三区| 少妇人妻综合久久中文字幕| 久久精品国产一区二区电影| 国产精品久久久久一区二区三区| 久久本道伊人久久| 国产99久久精品一区二区| 久久99国产综合精品| 久久久亚洲欧洲日产国码二区| 亚洲人成伊人成综合网久久久| 国产精品乱码久久久久久软件| 久久一本综合| 国产69精品久久久久APP下载| 久久精品综合网| 中文国产成人精品久久不卡| 中文字幕精品久久| 亚洲午夜久久久影院|