Arrays Are Fixed Size

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).』





Print Friendly, PDF & Email


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

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料