|
|
New C++ Operators |
|
cin and
cout C++ has also added the following operations for memory
management
new - allocates memory for the specified type and calls
the correct constructor for it once it has been allocated.
// allocates a memory block of 24 contiguous doubles, initializes it to
// zeroes, and assigns it to _array
double *_array = new double [24];
// allocates memory for a Matrix data type and runs the correct
// constructor
Matrix *m = new Matrix;
delete - runs the destructor for the specified object and
then deallocates it
delete m; // delete the matrix m
delete [] _array; // ensure to delete all elements of the array