|
||
|
Lesson 5
Objective
|
Why friend functions are needed
Write two add() functions to the matrix class |
|
|
Write two add() functions to the matrix class
Friend Function - Exercise
The keyword friend is a function specifier. It gives a nonmember function access to the hidden members of the class, and provides a method of escaping the data hiding restrictions of C++. However, you must have a good reason for escaping these restrictions, as they are both important to reliable programming. There are two reasons why you might use a friend function:
Click the Exercise button to write two add() functions to the matrix class--one a friend function and the
other a member function--and explain the advantages of defining one over the other.
Friend Function - Exercise |
||
|
|
||