📄 subject_48321.htm
字号:
<p>
序号:48321 发表者:wwww 发表日期:2003-07-30 12:17:23
<br>主题:函数声明int Fun() const 请问const代表什么意思?
<br>内容:函数声明int Fun() const 请问const代表什么意思?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Fang 回复日期:2003-07-30 14:06:22
<br>内容:Constant Member Functions<BR>C++ Specific <BR><BR>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.<BR><BR>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.<BR><BR>END C++ Specific<BR><BR>Example<BR><BR>// Example of a constant member function<BR>class Date<BR>{<BR>public:<BR> Date( int mn, int dy, int yr );<BR> int getMonth() const; // A read-only function<BR> void setMonth( int mn ); // A write function;<BR> // cannot be const<BR>private:<BR> int month;<BR>};<BR><BR>int Date::getMonth() const<BR>{<BR> return month; // Doesn't modify anything<BR>}<BR>void Date::setMonth( int mn )<BR>{<BR> month = mn; // Modifies data member<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -