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

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類(6)

            隨筆檔案(6)

            文章分類(2)

            文章檔案(2)

            Open source library

            Software often use

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久久久66精品片| 久久亚洲AV无码西西人体| 看久久久久久a级毛片| 一本一道久久精品综合| 污污内射久久一区二区欧美日韩 | 精品国产91久久久久久久| 国产亚洲精久久久久久无码AV| 亚洲色欲久久久久综合网| 99久久免费国产精品特黄| 青青青青久久精品国产| 国内精品伊人久久久久妇| 嫩草影院久久国产精品| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 精品久久久久久亚洲| 亚洲人成网站999久久久综合| 青青青国产成人久久111网站| 久久精品亚洲AV久久久无码| 久久乐国产精品亚洲综合| 久久99热国产这有精品| 久久人人爽人人爽人人片av高请| 尹人香蕉久久99天天拍| 久久一区二区三区99| 久久国产精品波多野结衣AV| 91精品国产综合久久婷婷| 色综合久久无码中文字幕| 久久精品国产亚洲αv忘忧草| 久久天天躁狠狠躁夜夜av浪潮| 91精品国产高清久久久久久91| 精品国产91久久久久久久| 91视频国产91久久久| 狠色狠色狠狠色综合久久| 亚洲午夜久久久精品影院 | 久久亚洲av无码精品浪潮| 久久久久女教师免费一区| 精品久久久久久无码人妻蜜桃| 久久久久久狠狠丁香| 国产精品日韩深夜福利久久| 久久久久久一区国产精品| 国产精品伦理久久久久久| 久久无码国产| 欧美亚洲国产精品久久|