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 >
Wrap
C/C++ Source or Header
|
1991-03-02
|
846b
|
27 lines
//******** 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
}