std::basic_ios
has a public constructor:
explicit basic_ios (std::basic_streambuf<CharT,Traits>* sb);
IMO, the sole reason for a class to have a public constructor is to use a standalone instance of that class in a program. If a class exists only to have other classes descend from it (as seems to be the case for basic_ios
), all of the class's constructors should be protected
. The constructors of std::ios_base
are all protected. But, for some reason, the designers of the standard made this one constructor of basic_ios
public.
basic_ios
is used as a base class for several stream types, and I can't envision a use case where you'd have one that wasn't at least a basic_istream
or basic_ostream
. Is there one?
basic_ios
ctor taking abasic_streambuf*
has been public since before you could dousing B::B;
. I expect that old implementations just had a proxy ctor:A(int x) : B(x) {}
- which works fine even ifB
's ctor isprotected
. – Orangy