/* varieties of arrays of objects */ using namespace std; #include class bigobject { public: int x; bigobject(int y) {x=y;} bigobject() {x = 99;} // default constructor }; int main() { bigobject *A[3]; // static array, dynamic objects A[0] = new bigobject(6); // etc... for each object cout << A[0]->x << endl; bigobject **B; // dynamic array and dynamic objects B = new bigobject*[3]; // creates an array of three pointers B[0] = new bigobject(7); // creates bigobject delete(B[0]); // deletes dynamic bigobject delete(B); // deletes dynamic array bigobject *C; // Pointer to a single object OR dynamic array of // static objects. C = new bigobject[5]; // creates dynamic array of objects cout << C[2].x << endl; bigobject D[3]; // static array and static objects, default constructor // used to create objects bigobject E[3] = { bigobject(2),bigobject(3),bigobject(5) }; cout << D[1].x << " and " << E[1].x << endl; return 0; } /* This program illustrates the creation of a static array of pointers to objects (A), a dynamic array of pointers to objects (B), a dynamic array of statically allocated objects (C), and a static array of statically allocated objects (D,E). D requires the definition of the "default" parameterless constructor, while E is created by calling constructors explicitly. Note that C can be used as pointer to a single, dynamic object, or a dynamic array of statically allocated objects. That is the call "C = new bigobject[5]" creates not just an array of pointers but an array of actual objects. Similarly, B can be used as a dynamic 2D array of objects. C++ gives you all these options, if you're confused, it's best to stick to a consistent form (dynamic array of dynamic objects, for example). That is, use C++ like Java. However, you will see these varieties in other people's code, and so you need to understand them. */