previous | start | next

## Member Functions (`const`)

- When the keyword `const` is used in the declaration, it must also be placed in the member function definition.

  >     void Product::print() const
  >     {
  >        cout << name
  >           << " Price: " << price
  >           << " Score: " << score << "\n";
  >     }

- The keyword `const` indicates that the member function will not modify the object that called it.
- When you refer to a data field in a member function, it denotes the data field of the object for which the member function was called.

  >     best.print();

- The object to which a member function is applied is called the implicit parameter.
- A parameter explicitly mentions in the function definition is called an explicit parameter.

  >     bool Product::is_better_than(Product b) const
  >     {
  >        if (b.price == 0) return false;
  >        if (price == 0) return true;
  >        return score / price > b.score / b.price;
  >     }

previous | start | next