1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Constructors and Destructors

If your abstract data types are going to be really "abstract" they need special support. When you declare an array, or a structure, or an integer in a function, C++ allocates the memory for you when the function is called. Similarly, when the function returns, C++ deallocates the memory. You too can allocate and deallocate memory.

Ideally we want to be able to say

{
Istack s1;// allocate space for stack s1
... // use the stack s1 }
// storage for s1 has been deallocated

*

and not have to do the
s1.init();

But stillwant to be able to say
s1.init(500);
which allocates a stack of non-default size. We would also like to be able do things like
Istack array_of_stacks[10];
Or even
Istack* ps; // pointer to a stack
ps = new Istack;
// allocate space for the stack
... // use the stack
dispose ps;
// deallocate the stack

*

* *

*

16-Mar-98

Page 9

C201/TAM/AGS