• <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++代碼參考與技巧大全》學習筆記
            青草久久久国产线免观| 久久久精品2019免费观看| 久久国产成人| 国产亚洲美女精品久久久2020| 漂亮人妻被中出中文字幕久久 | 久久久久亚洲AV无码麻豆| 亚洲精品无码成人片久久| MM131亚洲国产美女久久| 99久久精品国产一区二区三区| 人妻中文久久久久| 久久人爽人人爽人人片AV| 久久乐国产精品亚洲综合| 国内精品人妻无码久久久影院导航| 久久久久久亚洲Av无码精品专口| 久久成人18免费网站| 国产亚洲婷婷香蕉久久精品| 亚洲国产小视频精品久久久三级| 日本人妻丰满熟妇久久久久久| 国产农村妇女毛片精品久久| 久久久久免费看成人影片| 色播久久人人爽人人爽人人片AV| 久久国产一区二区| 久久偷看各类wc女厕嘘嘘| 中文字幕精品久久久久人妻| 成人精品一区二区久久| 99久久精品毛片免费播放| 久久精品国产男包| 中文字幕精品久久久久人妻| 久久精品国产免费一区| 无码伊人66久久大杳蕉网站谷歌| 久久久国产精品| 品成人欧美大片久久国产欧美| 欧美喷潮久久久XXXXx| 久久婷婷五月综合97色直播| 久久久久久无码国产精品中文字幕| 国产99久久精品一区二区| 人妻少妇久久中文字幕一区二区| 色青青草原桃花久久综合| 久久频这里精品99香蕉久| 亚洲精品无码久久久| 久久人人爽人人爽人人片AV不|