• <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>

            aslucky

            C++

             

            Constant Member Functions

            Declaring a member function with the const keyword specifies that the function is a "read-only" function that does not modify the object for which it is called.

            To declare a constant member function, place the const keyword after the closing parenthesis of the argument list. The const keyword is required in both the declaration and the definition. A constant member function cannot modify any data members or call any member functions that aren't constant.

            // constant_member_function.cpp
            class Date
            {
            public:
               Date( 
            int mn, int dy, int yr );
               
            int getMonth() const;     // A read-only function
               void setMonth( int mn );   // A write function; can't be const
            private:
               
            int month;
            }
            ;

            int Date::getMonth() const
            {
               
            return month;        // Doesn't modify anything
            }

            void Date::setMonth( int mn )
            {
               month 
            = mn;          // Modifies data member
            }

            int main()
            {
               Date MyDate( 
            741998 );
               
            const Date BirthDate( 1181953 );
               MyDate.setMonth( 
            4 );    // Okay
               BirthDate.getMonth();    // Okay
               BirthDate.setMonth( 4 ); // C2662 Error
            }

            posted on 2008-07-17 17:36 aslucky 閱讀(262) 評論(0)  編輯 收藏 引用 所屬分類: C++

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類(6)

            隨筆檔案(6)

            文章分類(2)

            文章檔案(2)

            Open source library

            Software often use

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            伊人色综合久久| 亚洲午夜久久久影院| 中文精品久久久久国产网址| 国内精品人妻无码久久久影院 | 国产成人精品综合久久久| 亚洲伊人久久大香线蕉综合图片| 伊人久久综合无码成人网| 久久久久亚洲av无码专区| 国产精品久久久久影院色| 久久久久成人精品无码| 久久精品国产久精国产一老狼| 久久99精品国产一区二区三区| 日韩影院久久| 久久久国产精品网站| 久久99精品国产99久久6| 伊人久久大香线蕉综合Av| 日本福利片国产午夜久久| 久久99热这里只频精品6| 国产精品成人无码久久久久久 | 无码人妻精品一区二区三区久久 | 日本高清无卡码一区二区久久| 亚洲AV日韩精品久久久久| 热99re久久国超精品首页| 亚洲精品久久久www| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 色综合久久久久无码专区| 日韩va亚洲va欧美va久久| 久久婷婷综合中文字幕| 色综合久久中文字幕无码| 久久婷婷五月综合色奶水99啪| 伊人久久成人成综合网222| 国内精品久久久久久久久| av无码久久久久不卡免费网站| 亚洲精品乱码久久久久久按摩 | 久久综合给久久狠狠97色| 性欧美大战久久久久久久| 久久最新免费视频| 亚洲国产二区三区久久| 精品久久久久久国产三级| 久久r热这里有精品视频| 久久国产精品-国产精品|