previous | start | next

Rule of 3, part 1: Destructor

Since the constructor dynamically allocates a C-string on the heap with new this memory needs to be deallocated when the Employee value itself is deallocated.

This is easy. Just write a destructor to delete the memory:

Employee::~Employee()
{
  delete [] name;
}
   


previous | start | next