Dynamic Objects
- The destructor is called implicitly with operator delete
// run time bindings
IntArray * xptr, * yptr; // pointers to type IntArray
...
{
IntArray * aptr = new IntArray; // ptr to default IntArray object
IntArray * bptr = new IntArray(100); // ptr to 100-element IntArray object
// Note that IntArray constructors are called as operator new is invoked
...
xptr = aptr; // simple assignment of integer type (addresses)
yptr = bptr; // simple assignment of integer type
...
}
// Note that aptr and bptr go out of scope here, but
// objects they point to are global scope and STILL EXIST
...
delete xptr; // destructor called
delete yptr; // destructor called