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

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            99久久精品国产麻豆| 99精品国产免费久久久久久下载| 精品久久久久久无码专区| 久久99国产精品久久| 久久亚洲2019中文字幕| 久久久久久亚洲精品成人| 国产精品va久久久久久久| 久久久无码精品亚洲日韩京东传媒| 久久久久久久97| 狠狠精品久久久无码中文字幕| 日韩一区二区久久久久久| 日韩精品久久久久久免费| 久久亚洲AV无码西西人体| 精品亚洲综合久久中文字幕| 无码人妻久久久一区二区三区| 中文字幕一区二区三区久久网站| 亚洲精品乱码久久久久久自慰| 欧美久久综合九色综合| 狠狠综合久久综合中文88| 99久久精品国产麻豆| 久久亚洲私人国产精品vA| 久久精品日日躁夜夜躁欧美| 日批日出水久久亚洲精品tv| 久久av免费天堂小草播放| 久久国产精品久久精品国产| 97r久久精品国产99国产精| 久久亚洲精品中文字幕| 国产激情久久久久久熟女老人| 久久久久人妻一区精品| 久久播电影网| 久久久久九九精品影院| 国产激情久久久久影院老熟女| 久久精品国产秦先生| 高清免费久久午夜精品| 国产精品免费看久久久| 亚洲国产精品人久久| 91麻豆精品国产91久久久久久| 精品久久久久中文字| 亚洲日本久久久午夜精品| 亚洲午夜久久久久久久久久| 亚洲av成人无码久久精品|