有影響.. 加了const.. x不能被更動..
--
※ Origin: 楓橋驛站<bbs.cs.nthu.edu.tw> ◆ From: n197.n203-107-5.eranet.net
補充:可以讓記憶體最佳化..............................
.............................................................
.............................................................
--
[1;32m※ Origin: [33m晨曦之鄉 [37m<bbs.cyut.edu.tw> [m
[1;31m◆ From: [36mM413-59.cyut.edu.tw [m
const和效能並沒有一定的關係...更別說記憶體最佳化了...
const的目的在type safe, 程式的正確性...
--
[1;32m※ Origin: [33m交大資工鳳凰城資訊站 [37m<bbs.csie.nctu.edu.tw> [m
[1;31m◆ From: [36msj8-172.dialup.seed.net.tw [m
" 也就是說, 在甚摸情況下, x 會被更改, 所以需要 const" !
※ 引述《ldc...@bbs.cs.nthu.edu.tw (流失..)》之銘言:
> ※ 引述《maninmi...@bbs.csie.nctu.edu.tw (canda)》之銘言:
> > void main()
> > {
> > int a =9;
> > print(a);
> > }
> > void print(const int& x)
> > { ^^^^^^ ------>這裡宣告 const, 有必要嗎 ?
> > cout << x...
> > }
> > 若不加 const, 會有影響嗎 ?
> 有影響.. 加了const.. x不能被更動..
--
[1;32m※ Origin: [33m交大資工鳳凰城資訊站 [37m<bbs.csie.nctu.edu.tw> [m
[1;31m◆ From: [36mtrt-on63-74.netcom.ca [m
� Are you sure ? Can anyone explain it ?
But I think "const" somewhat helps to
optimum the memory layout of some variable
declared as const in compile phase .
--
[1;33m※ Origin: [36m奇摩 大摩域 [37m<telnet://bbs.kimo.com.tw> [m
[1;35m◆ From: [1;32m210.63.66.73 [m
函式小ㄉ時候這一方面是幾乎沒有作用
因為你知道你ㄉ函式在幹麻
但是寫ㄉ比較大ㄌ
函式裡面又有函式..然後又有函式..又有函式...(bbs就是這種東西..)
那麼..的確令人吐寫
這等於是說加一層保險
有,總比沒有好,對吧!?
Occasionally, const does help compilers generate more efficient code.
However, that's not the purpose of const, and using const does
not guarantee the compiler would do any optimization.
--
[1;32m※ Origin: [33m交大資工鳳凰城資訊站 [37m<bbs.csie.nctu.edu.tw> [m
[1;31m◆ From: [36mt199-107.dialup.seed.net.tw [m