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

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久91这里精品国产2020| 久久久精品人妻一区二区三区蜜桃| 久久精品国产亚洲一区二区三区| 久久午夜伦鲁片免费无码| 国产成人精品综合久久久久 | 2020久久精品亚洲热综合一本| 亚洲午夜久久久精品影院 | 久久99久久99精品免视看动漫| 热99RE久久精品这里都是精品免费 | 国产精品久久久久久久午夜片| 色噜噜狠狠先锋影音久久| 久久久久夜夜夜精品国产| 久久99国产精品99久久| 久久精品国产亚洲欧美| 国产成人精品久久综合| 久久久久香蕉视频| 思思久久精品在热线热| 国产成人精品三上悠亚久久| 久久精品中文无码资源站 | 亚洲精品久久久www| 久久久久免费精品国产| 久久发布国产伦子伦精品| 久久久精品一区二区三区| 久久综合视频网站| 精品一二三区久久aaa片| 国内精品久久久人妻中文字幕| 久久精品国产一区二区三区日韩| 天天久久狠狠色综合| 伊人久久五月天| 国产精品久久久久久久久鸭| 精品久久久无码中文字幕| 久久久久久免费视频| 久久精品国产99久久无毒不卡| 91久久国产视频| 99久久精品免费看国产一区二区三区 | 久久精品国产影库免费看| 久久久久国产一区二区| 久久久亚洲欧洲日产国码二区| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 看全色黄大色大片免费久久久 | 久久精品国产国产精品四凭|