你們兩個說的是正解 :)
先前我的考慮不夠周密 :p
※ 引述《previewslave@kkcity.com.tw ( )》之銘言:
: ※ 引述《adrianshum.bbs@ptt.cc (Alien)》之銘言:
: > btw, 我是覺得有分別
: > 比如用回常用的例子, str[0]='x';
: > 第一個寫法會 pass compilation, 只是在 runtime 可能會出問題
: > (Stroustrup 的 The C++ Programming Lang 說是 behaviour undefined)
: > 後者則該不能通過 compilation
: > Alien
: Alien 說的好像比較正確。
: 我在想正確的說法是不是應該說成:
: const char * str = "string";
: 才是正確的寫法,而
: char * str = "string"';
: 則是邏輯錯誤的寫法,是 C++ 高手應該避免的,因為容易造成行為未定義。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.70.99.225