Interfaces and Implementations

However you write a stack class, the interface of a stack is defined by the operations push(), pop(), and depth(). These methods define the interface, and the actual code and data is called the implementation. It is very useful to separate these two different aspects of a class. A separate interface is easier to understand, and the implementation can be separately compiled.

Creating a Header File

To support separate compilation and to break a program into self-contained units, C++ encourages the use of header files. In the case of a function, a header file would contain prototypes, which would then be fully defined in another file. The equivalent for a class is similar. Within the class body are the member declarations, ...

Get C++ By Example: UnderC Learning Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.