previous | start | next

Rule of 3, part 2: Copy Constructor

The Employee copy constructor is a constructor whose parameter is another Employee. This other Employee is used to initialize the data members of this Employee.

The copy constructor will be used by the compiler to make a copy when an Employee variable is passed by value (or returned by value).

Employee::Employee(const Employee& other)
{
  name = new char[strlen(other.name) + 1];
  strcpy(name, other.name);
  salary = other.salary;
}


previous | start | next