HP aC++/HP C A.06.20 Programmer's Guide

Declare a class as a member of the class template (C2 below):
template<class T>
class C1 {
class C2;
// Additional details omitted
};
Declare a class in the context the template is declared within (C1 below):
class C1;
template<class T>
class C2 {
// details omitted
};
Overloading new[] and delete[] for Arrays
HP aC++ defines new and delete operators for arrays that are different from those
used for single objects. These operators, operator new[ ] ( ) and operator delete[
] ( ), can be overloaded both globally, and in a class. If you use operator new( ) to
allocate memory for a single object, you should use operator delete( ) to deallocate
this memory. If you use operator new[ ] ( ) to allocate an array, you should use
operator delete[ ] ( ) to deallocate it.
Usually, the allocation and deallocation of operators is overloaded for a particular class,
not globally. This overloading allows you to put all instances of a particular class on a
class-specific heap. You can then take control of allocation either for efficiency or to
accomplish other storage management functions, for example garbage collection. If
allocation and deallocation of single objects is overloaded, you may or may not want
to overload the operators for arrays. If the overloading was done for efficiency, it may
be that for arrays the default operator is the most efficient.
Example
# include <iostream.h>
class C {
public:
void* operator new[ ] (size_t); // new for arrays
void operator delete[ ] (void*); // delete for arrays
// additional class details omitted
};
void* C::operator new[ ] (size_t allocSize)
{
cout << Use operator new[ ] from class C\n;
// here, real usage would include allocation
return ::operator new[ ] (allocSize); // global operator
Overloading new[] and delete[] for Arrays 193