Pure virtual functions and virtual method dispatching leads to an incredibly powerful way of writing object-orientated code, which is called interfaces. An interface is a class that has no functionality; it only has pure virtual functions. The purpose of an interface is to define a behavior. A concrete class that derives from an interface must provide an implementation of all of the methods on the interface, and hence this makes the interface a kind of contract. Users of objects that implement an interface have a guarantee that the object that has the interface will implement all the methods of the interface. Interface programming decouples behavior from the implementation. Client code is only interested in behavior and they are ...

Get Beginning C++ Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.