By Robert S. Gray

Dr. Dobb's Journal March 1997

class Foo
{
public:
   Foo();
   ~Foo();
}
// allocation
Foo* pBar = (Foo *)malloc(10*sizeof(Foo));
// construction
for (i = 0; i< 10; i++)
   (pBar + i)->Foo::Foo();
// reallocation
pBar = (Foo *)realloc(pBar, 11*sizeof(Foo));
// construction of additional element
(pBar + 10)->Foo::Foo();
// destruction and deallocation
for (i = 0; i< 11; i++)
   (pBar + i)->Foo::~Foo();
free(pBar);

Example 1: HATs Off.

Back to Article


Copyright © 1997, Dr. Dobb's Journal