• <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人妻| 国产午夜福利精品久久| 人妻无码精品久久亚瑟影视 | 久久Av无码精品人妻系列| 亚洲乱码日产精品a级毛片久久 | 久久精品女人天堂AV麻| 久久香蕉国产线看观看精品yw| 久久精品人妻一区二区三区| 亚洲国产小视频精品久久久三级| 亚洲午夜久久久久妓女影院| 亚洲午夜无码AV毛片久久| 人妻精品久久久久中文字幕69| 亚洲国产精品久久66| 久久国产精品99国产精| 久久这里只有精品视频99| 久久国产精品波多野结衣AV| 影音先锋女人AV鲁色资源网久久| 99久久www免费人成精品| 欧美一区二区三区久久综合| 久久99精品久久久久久9蜜桃| 亚洲精品无码久久一线| 亚洲狠狠婷婷综合久久久久| 国产女人aaa级久久久级| 91久久香蕉国产熟女线看| 久久天堂AV综合合色蜜桃网| 午夜精品久久影院蜜桃| 亚洲欧美精品一区久久中文字幕| 97r久久精品国产99国产精| 99久久精品国内| 久久婷婷五月综合97色 | 午夜精品久久久久久久久| 2021国内久久精品| 人妻中文久久久久| 久久久亚洲精品蜜桃臀| 91久久精品国产91性色也| 91久久福利国产成人精品| 国产精品一区二区久久精品无码| 久久综合九色综合97_久久久 | 香港aa三级久久三级老师2021国产三级精品三级在 |