• <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í)筆記——索引隨筆
            日韩欧美亚洲综合久久影院Ds| 日韩人妻无码一区二区三区久久| 久久ZYZ资源站无码中文动漫| 久久综合综合久久97色| 久久久久久久综合综合狠狠| 精品国产乱码久久久久久呢| 久久99精品久久久久久| 久久www免费人成看国产片| 久久99这里只有精品国产| 99精品久久精品| 最新久久免费视频| 欧美激情精品久久久久| 亚洲精品午夜国产VA久久成人| 久久午夜电影网| 久久无码人妻一区二区三区| 久久久亚洲精品蜜桃臀| 精品午夜久久福利大片| 久久精品国产欧美日韩99热| 久久久久免费精品国产| 久久99精品久久久久婷婷| 久久婷婷五月综合色奶水99啪| 91亚洲国产成人久久精品| 久久精品国产亚洲AV高清热| 亚洲中文久久精品无码| 婷婷国产天堂久久综合五月| 久久精品成人欧美大片| 亚洲午夜久久影院| 99久久精品日本一区二区免费| 亚洲精品乱码久久久久久自慰| 人人妻久久人人澡人人爽人人精品 | 国产激情久久久久影院老熟女| 久久久久人妻精品一区二区三区| 热99RE久久精品这里都是精品免费 | 精品无码久久久久久久动漫| 久久福利青草精品资源站| 久久夜色精品国产噜噜麻豆| 中文无码久久精品| 三上悠亚久久精品| 国产精品久久久久无码av| 久久超乳爆乳中文字幕| 久久精品国产亚洲麻豆|