• <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í)筆記——索引隨筆
            久久国产一区二区| 久久93精品国产91久久综合| 亚洲AV伊人久久青青草原| 久久精品国产一区二区| 精品久久久久久久国产潘金莲| 狠狠色丁香婷婷久久综合| 99久久综合狠狠综合久久止| 久久国产成人午夜aⅴ影院| 99精品国产99久久久久久97| 精品国产一区二区三区久久久狼 | 一本色综合网久久| 久久精品亚洲一区二区三区浴池| 国产精品免费看久久久香蕉| 狠狠色婷婷久久一区二区| 久久精品一区二区三区中文字幕| 久久影院综合精品| 国产精品一区二区久久精品涩爱| 日本久久久久久中文字幕| 久久久噜噜噜久久中文福利| 亚洲综合久久夜AV | 91精品日韩人妻无码久久不卡| 久久99久久99精品免视看动漫 | 亚洲AV日韩精品久久久久| 精品久久久久久无码国产| www.久久热| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 久久er国产精品免费观看2| 香蕉99久久国产综合精品宅男自| 精品亚洲综合久久中文字幕| 亚洲精品乱码久久久久久久久久久久| 久久人人爽人爽人人爽av| 99久久久久| 久久精品这里只有精99品| 99久久国产综合精品成人影院| 97久久超碰国产精品2021| 72种姿势欧美久久久久大黄蕉| 久久中文骚妇内射| 99热成人精品热久久669| 久久免费线看线看| 国内精品久久久久久久亚洲| 久久91精品综合国产首页|