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

            導航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類(6)

            隨筆檔案(6)

            文章分類(2)

            文章檔案(2)

            Open source library

            Software often use

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久99精品国产麻豆宅宅| 久久偷看各类wc女厕嘘嘘| 91精品久久久久久无码| 无码任你躁久久久久久老妇| 97精品伊人久久大香线蕉| 久久男人Av资源网站无码软件| 色噜噜狠狠先锋影音久久| 久久天天躁狠狠躁夜夜avapp| 国产精品99久久免费观看| 亚洲国产精品嫩草影院久久| 久久久久久亚洲AV无码专区| 久久久久久久免费视频| 99久久精品国产一区二区| 99精品久久精品一区二区| 久久本道久久综合伊人| 人妻精品久久无码区| 要久久爱在线免费观看| 亚洲国产精品久久久久婷婷老年| 国产成人久久精品一区二区三区| 精品一久久香蕉国产线看播放| 无码AV中文字幕久久专区| 久久人妻少妇嫩草AV蜜桃| 99久久精品国产一区二区蜜芽| 国产成人精品白浆久久69| 午夜天堂av天堂久久久| 久久无码AV一区二区三区| 久久久久国产精品嫩草影院| 欧美伊香蕉久久综合类网站| 精品久久久久久成人AV| 欧洲精品久久久av无码电影| 久久AV无码精品人妻糸列| 2019久久久高清456| 久久久国产视频| 亚洲日本久久久午夜精品| 伊人色综合久久天天网| 久久久久久国产a免费观看黄色大片 | 无码伊人66久久大杳蕉网站谷歌| 亚洲国产精品无码久久青草| 一级女性全黄久久生活片免费 | 婷婷久久综合九色综合绿巨人| 精品久久久久久久中文字幕|