|
||
| Lesson 8
Objective
|
Using a member function
Add a member function to the ch_stack struct. |
|
|
Member functions are written just like any other functions.
Member Function - Exercise
One difference, though, is they can use the data member names as is. Thus, the member functions in ch_stack use top and s in an unqualified manner. When invoked on a particular object of type ch_stack, the member functions act on a specified member of that object. Member functions that are defined within the struct are implicitly inline. As a rule, only short, heavily used member functions should be defined with the struct. Other member functions should be defined external to the struct. We will look at defining external member functions in the next module.
Click the Exercise link to add a member function to the ch_stack struct.
Member Function - Exercise |
||
|
|
||