==> 在 Remins.bbs@csie.nctu.edu.tw (鬼谷子) 的文章中提到:
> 有兩個 Function() 宣告如下
> void GetWindowRect(Rect& rect) const;
=================
我不知道我講得對不對..還望大大們幫忙..
我是用C++來說的..
在the C++ programming language page.229
最底下出現一句話..
the const after the (empty) argument list in the function declaration..
> Rect GetWindowRect() const;
> 其最後所加之 const 有何意義?
> 與 const int var ;所代表 var 不可改變有何不同?
======
若是這樣看的話..這樣的宣告好像是錯的..
你未給初值..
也是同一本書上有說..第94頁的某一句話..
a constant must be initialized..
--
ID: szu
Name: 思思 Michael Liang
Email: lmings@ms7.url.com.tw
一位來自南台灣喜歡程式設計正努力設計程式的電腦人
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
> -------------------------------------------------------------------------- <
發信人: qpwoeiru.bbs@cis.nctu.edu.tw (Talk__戰將), 看板: Programming
標 題: Re: 關於 C const 的運用問題?
發信站: 交大資科_BBS (Wed Jan 27 05:07:31 1999)
轉信站: Ptt!news.ntu!ctu-gate!news.nctu!news.cis.nctu!cis_nctu
==> 在 szu@cis_nctu (思思 Michael Liang) 的文章中提到:
> ==> 在 Remins.bbs@csie.nctu.edu.tw (鬼谷子) 的文章中提到:
> > 有兩個 Function() 宣告如下
> > void GetWindowRect(Rect& rect) const;
> =================
> 我不知道我講得對不對..還望大大們幫忙..
> 我是用C++來說的..
> 在the C++ programming language page.229
> 最底下出現一句話..
> the const after the (empty) argument list in the function declaration..
你好像在解釋他的宣告,基本上這應該算faq,const 宣告在函式後
1.要使用該函式的object 本身不會被更改到,否則就發生error
2.讓const object 能使用該function
> > Rect GetWindowRect() const;
> > 其最後所加之 const 有何意義?
> > 與 const int var ;所代表 var 不可改變有何不同?
> ======
> 若是這樣看的話..這樣的宣告好像是錯的..
> 你未給初值..
> 也是同一本書上有說..第94頁的某一句話..
> a constant must be initialized..
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
> -------------------------------------------------------------------------- <
發信人: veery.bbs@bbs.kimo.com.tw (veery), 看板: Programming
標 題: Re: 關於 C const 的運用問題?
發信站: 奇摩大摩域 (Fri Jan 29 11:12:50 1999)
轉信站: Ptt!news.ntu!bbs.ee.ntu!freebsd.ntu!news.cs.nthu!bbsnews.kimo.com.tw!K
※ 引述《Remins.bbs@csie.nctu.edu.tw (鬼谷子)》之銘言:
: 有兩個 Function() 宣告如下
: void GetWindowRect(Rect& rect) const;
: Rect GetWindowRect() const;
: 其最後所加之 const 有何意義?
: 與 const int var ;所代表 var 不可改變有何不同?
: 何時才是使用 const 的最佳時機?
: 因為變數只有改變與不能改變兩種,總不能就此將變數加上 const!
C++ Specific R
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 const member function cannot modify any
data members or call any member functions that aren't constant.
以上引用自vc 5.0 help
--
※ Origin: 奇摩 大摩域 (bbs.kimo.com.tw) ◆ From: 210.61.204.201