previous
|
start
|
next
Automatic Memory Management
A
Department
object contains a pointer to an
Employee
object.
When the
Department
object is destroyed (goes out of scope, for example) the
Employee
object is leaked.
In C++, you can define a
destructor
, a function that is called when an object is about to go out of scope.
The destructor for the
Department
class should delete the receptionist pointer.
Department::~Department() { delete receptionist; }
Note that calling delete on a
NULL
pointer is safe, so you don't need a special case for that situation.
previous
|
start
|
next