Another Object Lesson: Objects, Inheritance, and References
The ostream
and ofstream
classes bring an interesting property of references to the fore. As you may recall from Chapter 6, “Branching Statements and Logical Operators,” objects of the ofstream
type can use ostream
methods, allowing file input/output to use the same forms as console input/output. The language feature that makes it possible to pass features from one class to another is called inheritance, and Chapter 13, “Class Inheritance,” discusses this feature in detail. In brief, ostream
is termed a base class (because the ofstream
class is based on it) and ofstream
is termed a derived class (because it is derived from ostream
). A derived class inherits the base class methods, which ...
Get C++ Primer Plus 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.