• <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 閱讀(269) 評論(0)  編輯 收藏 引用 所屬分類: C++

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類(6)

            隨筆檔案(6)

            文章分類(2)

            文章檔案(2)

            Open source library

            Software often use

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            AV无码久久久久不卡网站下载| 麻豆AV一区二区三区久久| 97久久香蕉国产线看观看| 亚洲午夜久久久久妓女影院| 久久99精品国产自在现线小黄鸭| 久久精品欧美日韩精品| 久久国产精品一区| 久久精品国产99久久久古代| 潮喷大喷水系列无码久久精品| 久久狠狠高潮亚洲精品| 91精品国产综合久久香蕉 | 国产日产久久高清欧美一区| 国产日韩久久久精品影院首页| 亚洲伊人久久精品影院| 久久久91精品国产一区二区三区| 三级三级久久三级久久| 99久久夜色精品国产网站| 少妇人妻综合久久中文字幕| 青青青国产精品国产精品久久久久 | 人妻丰满?V无码久久不卡| 亚洲αv久久久噜噜噜噜噜| 日韩AV毛片精品久久久| 久久99精品国产麻豆| 色欲综合久久躁天天躁| 久久九九有精品国产23百花影院| 久久久久久久免费视频| 天堂无码久久综合东京热| 99久久99这里只有免费的精品| 亚洲国产精品一区二区三区久久| 国产综合成人久久大片91| 久久久青草青青亚洲国产免观| 亚洲AV成人无码久久精品老人| 久久久黄色大片| 久久福利资源国产精品999| 久久久久免费视频| 精品久久久久久久中文字幕| 亚洲国产成人久久综合碰碰动漫3d| 久久99国产精品尤物| 国产精品久久久久久搜索| 久久国产精品-国产精品| 欧美一区二区精品久久|