• <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í)筆記——索引隨筆
            欧美激情一区二区久久久| 国内精品免费久久影院| 久久青青色综合| 人妻丰满AV无码久久不卡| 国产成人精品白浆久久69| 精品久久久久中文字| 久久久久久久波多野结衣高潮| 国产免费久久精品99久久| 精品久久久久久久久免费影院| 人妻精品久久无码区| 国产精品永久久久久久久久久| 欧美精品九九99久久在观看| 久久亚洲国产成人精品性色| 久久国产免费| 国产精品久久久久影视不卡| 久久综合伊人77777| 国产精品一久久香蕉产线看| 久久亚洲精品成人无码网站| 99久久精品免费观看国产| 狠狠精品久久久无码中文字幕| 亚洲国产精品婷婷久久| 久久人与动人物a级毛片| 久久国产乱子伦精品免费午夜| 72种姿势欧美久久久久大黄蕉| 噜噜噜色噜噜噜久久| 久久国产热这里只有精品| 亚洲精品高清久久| 2021久久国自产拍精品| 亚洲欧美伊人久久综合一区二区 | 久久久久久久久无码精品亚洲日韩 | 久久久久99精品成人片试看| 亚洲&#228;v永久无码精品天堂久久| 久久精品无码一区二区无码| 久久SE精品一区二区| 久久久高清免费视频| 亚洲欧美成人久久综合中文网 | 久久人妻AV中文字幕| 国产成人精品久久| 99久久99久久精品国产片果冻| 2021国内久久精品| 亚洲精品无码久久久久sm|