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

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            少妇人妻综合久久中文字幕| 伊人久久综合无码成人网| 国产91色综合久久免费| 国产精品一久久香蕉产线看| 国产精品免费久久久久影院 | 9久久9久久精品| Xx性欧美肥妇精品久久久久久| 久久福利片| 97久久超碰国产精品旧版| 久久精品成人影院| 久久精品毛片免费观看| 久久国产视频网| 2021久久国自产拍精品| 一本综合久久国产二区| 精品久久8x国产免费观看| 色99久久久久高潮综合影院| 国产精品岛国久久久久| 久久久久久久久久久久久久| 麻豆精品久久精品色综合| 无遮挡粉嫩小泬久久久久久久 | 国产成人久久精品一区二区三区| 久久精品国产第一区二区| 久久av无码专区亚洲av桃花岛| 无码人妻少妇久久中文字幕| 一本大道加勒比久久综合| 久久超乳爆乳中文字幕| 亚洲精品乱码久久久久久蜜桃不卡 | 97久久久精品综合88久久| 亚洲AV无码久久精品成人| 一本色道久久88综合日韩精品 | 三级片免费观看久久| 久久久久久极精品久久久 | 亚洲国产高清精品线久久| 久久精品国产99久久丝袜| 91精品日韩人妻无码久久不卡| 日韩精品久久久久久久电影蜜臀 | 久久99中文字幕久久| 久久96国产精品久久久| 99久久精品免费国产大片| 99热热久久这里只有精品68| 国产精品午夜久久|