• <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久久国产亚洲综合精品| 亚洲欧洲久久久精品| 亚洲中文字幕无码久久综合网| 狠狠色综合网站久久久久久久高清 | 国产精品久久久久久久久鸭| AAA级久久久精品无码区| 亚洲欧美日韩精品久久亚洲区 | 日韩人妻无码精品久久久不卡| 东京热TOKYO综合久久精品| 久久久久国产一级毛片高清板| 欧美亚洲国产精品久久高清| 久久亚洲精品视频| 无码国内精品久久人妻| AA级片免费看视频久久| 欧美牲交A欧牲交aⅴ久久| 欧美色综合久久久久久| 久久综合久久综合九色| 亚洲精品乱码久久久久久蜜桃不卡| 国产精品久久久天天影视| 人妻无码精品久久亚瑟影视| 久久精品国产99国产精品| 国产精品一久久香蕉国产线看观看 | 色天使久久综合网天天| 国产精品成人精品久久久| 日韩精品久久久久久久电影蜜臀| 亚洲精品乱码久久久久久蜜桃| 久久成人精品| 久久精品视屏| 久久人妻少妇嫩草AV无码蜜桃| 香蕉久久夜色精品国产小说| 久久精品视频网| 久久精品一区二区国产| 中文字幕亚洲综合久久| 久久这里只有精品久久| 国产午夜精品久久久久九九电影| 99久久精品日本一区二区免费| 97热久久免费频精品99|