• <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í)筆記——索引隨筆
            久久久久高潮综合影院| 久久天天躁狠狠躁夜夜avapp| 国产精品久久国产精品99盘| 亚洲国产精品久久| 伊人色综合九久久天天蜜桃| 亚洲女久久久噜噜噜熟女| 99久久人人爽亚洲精品美女 | 亚洲乱码中文字幕久久孕妇黑人| 国内精品久久久久影院优| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲国产欧美国产综合久久| 国产福利电影一区二区三区,免费久久久久久久精 | 亚洲精品WWW久久久久久| 国产高潮国产高潮久久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 久久久这里有精品中文字幕| 久久精品国产精品亚洲毛片| 久久中文字幕精品| 亚洲狠狠综合久久| 好久久免费视频高清| 亚洲国产精品无码久久SM| 亚洲人成无码www久久久| 国产ww久久久久久久久久| 久久精品99久久香蕉国产色戒| 色播久久人人爽人人爽人人片AV| 国产91久久综合| 99久久精品久久久久久清纯| 久久福利青草精品资源站| 国产精品久久久亚洲| 国产成人久久精品一区二区三区| 亚洲愉拍99热成人精品热久久| 久久亚洲sm情趣捆绑调教 | 99久久精品国产毛片| 99久久国产综合精品五月天喷水 | 99久久婷婷免费国产综合精品| 久久亚洲精品人成综合网| 亚洲午夜久久久久久久久电影网| 久久久精品人妻一区二区三区蜜桃| 精品久久久一二三区| 亚洲av伊人久久综合密臀性色| 久久99精品久久只有精品 |