C++ Primer 4/e 在Arrays这里有一个要小心的地方:‘Some compilers allow array assignment as a compiler extension. If you intend to run a given program on more than one compiler, it is usually a good idea to avoid using nonstandard compiler-specific features such as array assignment.’
另外一个警告:‘Unlike the vector type, there is no push_back or other operation to add elements to the array. Once we define an array, we cannot add elements to it.
If we must add elements to the array, then we must manage the memory ourselves. We have to ask the system for new storage to hold the larger array and copy the existing elements into that new storage. We’ll see how to do so in Section 4.3.1 (p. 134).’
中文版的是这样说:‘有些编译器允许array赋值操作,视为一种编译器扩充功能。如果你希望程式通过一个以上的编译器,最好避免使用非标准的编译器特有性质,例如这里所说的array赋值操作。
不同于vector,array并没有push_back()或其他用来增添元素的操作。一旦我们定义了一个array,就不能再扩展它。
如果一定要为array添加元素(空间),就必须自我管理记忆体。我们必须向系统要求新空间以存放较大的array,然后复制现有元素到新空间去。’
原来阵列没有push_back真是不方便。