O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.1. How to Implement a Class

OK, where do we start? In general, we start with an abstraction. Consider a stack. A stack is a fundamental abstraction of computer science. It allows for the nesting and retrieval of values in a last-in, first-out sequence. We nest values by pushing a new value onto the stack, and we retrieve them by popping the last value pushed on the stack. Other operations that users often require are to ask whether a stack is full or empty and to determine the size of the stack. A stack may also support peeking at the last value pushed on the stack.

In the description of a stack I italicized the words that represent operations that users will likely want to apply to objects of our stack class.

What type of elements should ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required