C++ Primer 4/e 在pointers這裡有一個忠告:『Pointers and arrays are surprisingly error-prone. Part of the problem is conceptual: Pointers are used for low-level manipulations and it is easy to make bookkeeping mistakes. Other problems arise because of the syntax, particularly the declaration syntax used with pointers.
Many useful programs can be written without needing to use arrays or pointers. Instead, modern C++ programs should use vectors and iterators to replace general arrays and strings to replace C-style array-based character strings.』
中文版的是這樣說:『Pointers 和 Arrays 容易出錯的程度令人驚訝。部份問題是概念性的:pointers用來進行低階操作,因此容易犯下簿記錯誤(bookkeeping mistakes)。另一個問題出在語法,特別是pointers的宣告語法。
很多有用的程式並不需要使用arrays 或pointers就能寫成。現今的C++程式應該使用vectors 和iterators取代arrays,並使用strings取代C 風格的、以array為基礎的字元字串。』
看來我將越來越喜歡C++了,少用指標是一大福音,少用陣列需要時間來改變。