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

            常用鏈接

            留言簿(8)

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

             

                  structC語言的概念,在標準C中,標準C中是不允許在結構中聲明函數的,而在C++的類中是可以聲明函數的。

                  但是在C++structclass意義一樣,唯一不同就是struct里面默認的訪問控制是publicclass中默認的訪問控制是private。在C++struct中也可以構造函數、析構函數、它們之間也可以繼承

                  下面的代碼演示了struct繼承的例子:

            #include<iostream.h>
            /*******************************************************/
            /* 動物基類
            /******************************************************
            */

            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;
            }
            ;
            /*******************************************************/
            /* 主函數
            /******************************************************
            */

            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;
            }

            代碼的輸出為:


            想要獲得更多內容,可點擊:《Visuanl C++代碼參考與技巧大全》學習筆記——索引隨筆
            posted on 2010-02-15 17:20 煙皚 閱讀(759) 評論(0)  編輯 收藏 引用 所屬分類: 《Visual C++代碼參考與技巧大全》學習筆記
            久久亚洲AV成人无码国产| 久久久久亚洲精品中文字幕| 无码国内精品久久综合88| 狠狠88综合久久久久综合网| 精品久久久无码中文字幕| 精品久久久久久无码中文字幕一区| 97精品国产91久久久久久| 久久精品无码一区二区WWW| 国产精品欧美久久久久天天影视| 奇米影视7777久久精品| .精品久久久麻豆国产精品| 久久噜噜久久久精品66| 国内精品久久九九国产精品| 久久精品无码一区二区无码| 欧美噜噜久久久XXX| 久久丝袜精品中文字幕| 久久精品免费一区二区三区| 久久午夜无码鲁丝片秋霞 | 亚洲精品午夜国产va久久| 国产—久久香蕉国产线看观看| 综合网日日天干夜夜久久| 久久亚洲精品人成综合网| 久久综合久久综合亚洲| 国产午夜精品理论片久久 | 亚洲精品无码久久毛片| 久久久WWW免费人成精品| 久久国产香蕉一区精品| 久久精品国产99久久久| 青青草原综合久久大伊人| 一本久久免费视频| 四虎亚洲国产成人久久精品| 久久91精品国产91久| 欧美久久一区二区三区| 久久久久久久综合综合狠狠| 婷婷综合久久狠狠色99h| 久久精品国产免费| 久久99国产精品久久99果冻传媒| 久久精品天天中文字幕人妻 | 伊人久久大香线蕉综合热线| 亚洲中文字幕伊人久久无码| 伊人热热久久原色播放www|