previous | start | next

## Constructors with Parameters

- Sometimes a constructor gets more complex because one of the data fields is itself an object of another class with its own constructor.
- Example: suppose we modify the `Employee` class so that each `Employee` has scheduled work hours.

  >     class Employee
  >     {
  >     public:
  >        Employee(string employee_name, double initial_salary,
  >           int arrive_hour, int leave_hour);
  >        . . .
  >     private:
  >        string name;
  >        double salary;
  >        Time arrive;
  >        Time leave;
  >     };

  The constructor must initialize the time fields using the `Time()` constructor.

  >     Employee::Employee(string employee_name, double initial_salary,
  >        int arrive_hour, int leave_hour)
  >     {
  >        name = employee_name;
  >        salary = initial_salary;
  >        arrive = Time(arrive_hour, 0, 0);
  >        leave = Time(leave_hour, 0, 0);
  >     }

previous | start | next