OO Encapsulation  «Prev  Next»
Lesson 8 Using a member function
Objective Add a member function to the ch_stack struct.

Using a Member Function in C++

Member functions are written just like any other functions.
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.

C++ Member Function - Exercise

At the level of programming, a class is a data structure with
  1. data members for representing the various properties of the different object instances of the class, and
  2. with member functions for representing the behavior of the class.

Click the Exercise link to add a member function to the ch_stack struct.
C++ Member Function - Exercise