home *** CD-ROM | disk | FTP | other *** search
- //******** Listing 9 ********************** OBJARRAY.CPP **
- // OBJARRAY.CPP : Creating arrays of objects
- // (c) C Gazette. See Listing 1 for usage.
- //*********************************************************
-
- #include <stdio.h>
- #include "object.hpp"
-
- class object_a : public object {
- public:
- object_a() : object('a') {}
- };
-
- class object_b : public object {
- public:
- object_b() : object('b') {}
- };
-
- main() {
- object_a X[10]; // stack-based array of objects
- X[1].print(); // function call for stack-based array
- object_b* ob = new object_b[7]; // heap-based array of objects
- ob[1].print(); // function call is exactly the same!
- delete [7]ob; // Pre-ANSI C++ style for deleting an array
- // delete []ob; // ANSI C++ array deletion
- object Y[] = { 'u', 'v', 'w' }; // aggregate initialization
- }