Avoid Pointers and Arrays

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為基礎的字元字串。』


achi’s English Blog




發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *