22.16. Resizable arrays

Suppose you want to have an array that holds, say, cCritter objects. There are really three options: maintain your own C-style array, use an array template from the ANSI C++ STL Standard Template Library, or use the Microsoft CArray template.

To maintain an array yourself means using a declaration like cCritter *_critter or cCritter _critter[]. (Note that C regards these two declarations as equivalent; in C an array is simply a pointer.) If you do this, you would also need an int _critter_count variable to keep track of the current number of points stored. And you’d either have to preallocate _critter to some generously large size (and worry about eventually writing off the end), or you’d have to keep reallocating the ...

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.