• <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中文字幕久久专区| 国内精品久久久久影院免费| 九九精品99久久久香蕉| 亚洲国产精品人久久| 一级做a爰片久久毛片毛片| 精品国产日韩久久亚洲| 国产精品对白刺激久久久| 久久国产成人午夜AV影院| 亚洲欧洲日产国码无码久久99| 久久久久久狠狠丁香| 欧美亚洲日本久久精品| 香蕉久久夜色精品升级完成| 色综合久久88色综合天天| 精品人妻伦九区久久AAA片69| 伊人丁香狠狠色综合久久| 亚洲综合伊人久久综合| 国产精品VIDEOSSEX久久发布| 狼狼综合久久久久综合网| 久久综合给合综合久久| 久久免费精品一区二区| 久久久久久夜精品精品免费啦| 色偷偷88欧美精品久久久| 99久久精品国产综合一区| 久久99精品久久只有精品| 狠狠综合久久综合88亚洲| 久久久久久国产精品无码下载| 国产精品禁18久久久夂久 | av无码久久久久不卡免费网站| 伊人久久国产免费观看视频| 国产真实乱对白精彩久久| 久久中文娱乐网| 久久夜色精品国产亚洲| 国产成人久久精品激情| 国内精品久久人妻互换| 久久久久亚洲精品无码蜜桃| 性做久久久久久久| 久久国产高潮流白浆免费观看| 国产成人精品综合久久久| 亚洲中文字幕无码久久综合网| 亚洲国产精品无码久久|