home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CGAZV5N3.ZIP / OBJARRAY.CPP < prev    next >
C/C++ Source or Header  |  1991-03-02  |  846b  |  27 lines

  1. //******** Listing 9 ********************** OBJARRAY.CPP **
  2. // OBJARRAY.CPP : Creating arrays of objects
  3. // (c) C Gazette. See Listing 1 for usage.
  4. //*********************************************************
  5.  
  6. #include <stdio.h>
  7. #include "object.hpp"
  8.  
  9. class object_a : public object {
  10. public:
  11.   object_a() : object('a') {}
  12. };
  13.  
  14. class object_b : public object {
  15. public:
  16.   object_b() : object('b') {}
  17. };
  18.  
  19. main() {
  20.   object_a X[10];   // stack-based array of objects
  21.   X[1].print();     // function call for stack-based array
  22.   object_b* ob = new object_b[7];  // heap-based array of objects
  23.   ob[1].print();    // function call is exactly the same!
  24.   delete [7]ob;     // Pre-ANSI C++ style for deleting an array
  25.   // delete []ob;   // ANSI C++ array deletion
  26.   object Y[] = { 'u', 'v', 'w' };  // aggregate initialization
  27. }