OO Encapsulation  «Prev 

Member Invocation Example in C++

When invoked on a particular object of type ch_stack, the member functions act on the specified member in that object.
The following example illustrates these ideas. If two ch_stack variables

ch_stack data, operands;

data.reset();
operands.reset();

invoke the member function reset, which has the effect of setting both data.top and operands.top to EMPTY.
If a pointer to ch_stack

ch_stack* ptr_operands = &operands;

ptr_operands -> push('A');

invokes the member function push, which has the effect of incrementing operands.top and setting operands.s[top] to 'A'.
One last observation: the member function top_of() had its name changed from the previous implementation because of a naming conflict.