previous | start | next

## Comparing Member Functions with Nonmember Functions

- Consider the nonmember function

  >     void raise_salary(Employee& e, double percent)
  >     {
  >        double new_salary = e.get_salary()
  >           * (1 + percent / 100);
  >        e.set_salary(new_salary);
  >     }

  versus the memeber function

  >     void Employee::raise_salary(double percent)
  >     {
  >        salary = salary * (1 + percent / 100);
  >     }

- A nonmember function is called with two explicit parameters.

  >     raise_salary(harry, 7);

- A member function is called using the dot notation, with one explicit parameter and one implicit parameter.

  >     harry.raise_salary(7);

- A member function can invoke another member function on the implicit parameter without using the dot notation.

  >     void Employee::print() const
  >     {
  >        cout << "Name: " << get_name()
  >           << "Salary: " << get_salary()
  >           << "\n";
  >     }

previous | start | next