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++了,少用指标是一大福音,少用阵列需要时间来改变。