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

            常用鏈接

            留言簿(8)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

             

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

                  但是在C++structclass意義一樣,唯一不同就是struct里面默認(rèn)的訪問控制是publicclass中默認(rè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í)筆記——索引隨筆
            2022年国产精品久久久久| 天天做夜夜做久久做狠狠| 色综合久久久久综合体桃花网 | 久久久久久精品无码人妻| 久久AV无码精品人妻糸列| 久久免费视频网站| 亚洲综合久久久| 91久久香蕉国产熟女线看| 久久精品人人做人人爽电影| 久久精品国产亚洲网站| 欧美黑人激情性久久| 国内精品久久久久影院网站 | 国产一区二区久久久| 99久久国产综合精品成人影院 | 无码精品久久久天天影视| 亚洲综合久久综合激情久久| 亚洲中文久久精品无码ww16 | 91精品国产综合久久香蕉 | 久久久久久久亚洲Av无码| 久久99久久成人免费播放| 婷婷久久香蕉五月综合加勒比| 午夜精品久久久久9999高清| 亚洲国产精品热久久| 99久久精品影院老鸭窝| 久久久婷婷五月亚洲97号色| 国产成人精品综合久久久| 一本色道久久88综合日韩精品| 91久久九九无码成人网站| 久久精品免费观看| 99久久国产热无码精品免费| 久久99精品久久只有精品| 久久精品不卡| 久久性生大片免费观看性| 国产91久久综合| 精品99久久aaa一级毛片| 久久精品无码一区二区三区免费| 93精91精品国产综合久久香蕉| 岛国搬运www久久| 亚洲国产婷婷香蕉久久久久久| 四虎亚洲国产成人久久精品| 一97日本道伊人久久综合影院|