Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library User's Guide

38.2 Choosing a Base Class

The first question is: Which of the standard stream classes shall be the base class? The answer fully depends on the kind of addition or modification you want to make. In our case, we want to add formatting information, which depends on the stream's character type since the format string is a sequence of narrow characters. As we show later on, the format string must be expanded into a sequence of the stream's character type for use with the stream's locale. Consequently, a good choice for a base class is a specialization of std::basic_iostream, and since we want the format string to impact only output operations, the best choice is std::basic_ostream.

In general, you choose a base class by looking at the kind of addition or modification you want to make and comparing it with the characteristics of the stream classes.

Derivations from std::basic_istream, std::basic_ostream, or std::basic_iostream are the most common cases, because you typically want to modify or add input and output operations.

If you derive from std::ios_base or std::basic_ios, you do not inherit any input and output operations; you do this if you really want to reimplement all of them or intend to implement a completely different kind of input or output operation, such as unformatted binary input and output.

Derivations from file or string streams such as basic_{i,o}fstream or basic_{i,o}stringstream are equally rare, because they make sense only if file- or string-related data or services must be added or modified.

NOTE -- Choose basic_istream, basic_ostream, or basic_iostream as a base class when deriving new stream classes, unless you have good reason not to do so.

Previous fileTop of DocumentContentsIndex pageNext file