std::ios_base::ios_base(3)
β¨ std::ios_base::ios_base β¨
okay bestie, so this is the std::ios_base::ios_base manual page from the C++ Standard Library β aka the origin story of how stream base objects get (and don't get) constructed π
buckle up.
πΈ SYNOPSIS πΈ
private: (until C++11)
ios_base( const ios_base& );
public: (1) (since C++11)
ios_base( const ios_base& ) = delete;
protected: (2)
ios_base();
so here's the tea on these two constructors, no cap π«
- the copy constructor is private (until C++11) and deleted (since C++11) β literally because streams are not copyable, periodt. you cannot duplicate a stream, it's giving one-of-a-kind main character energy π
- the default constructor is protected: only derived classes may construct
std::ios_base. and like, the internal state is undefined after construction π so the derived class must callstd::basic_ios::init()to complete initialization before first use or before the destructor β otherwise the behavior is undefined. not me warning you twice, but fr fr, that's the rule π
β οΈ okay so the undefined-behavior part is serious: skip that init() call and everything's cursed, no takebacks.
π¦ NOTES π¦
the same whole situation applies to the constructors of the next class in the I/O hierarchy, std::basic_ios. and the further-derived classes (std::istream and std::ostream) are always constructed with a concrete stream buffer object and call std::basic_ios::init() β possibly more than once, iykyk β to complete initialization of their virtual base. it's giving teamwork honestly π«Ά
π Defect reports π
the following behavior-changing defect reports were applied retroactively to previously published C++ standards. (yes, they went back and fixed the lore πβ¨)
- LWG 50 β applied to C++98. behavior as published: the copy constructor was not specified. correct behavior: specified as private.
- LWG 220 β applied to C++98. behavior as published: the behavior of destroying a
std::ios_baseobject before calling itsinit()was not clear. correct behavior: the behavior is undefined in this case. - LWG 1249 β applied to C++98. behavior as published: initialization did not need to be completed before first use. correct behavior: initialization also needs to be completed.
like, they really said "let's clarify the vibes" and honestly? slay π
that's the whole page bestie β every flag, every caveat, every DR, all accounted for π
and that's a wrap! this iconic little page comes to you from cppreference.com, dated 2024.06.10, under the title std::ios_base::ios_base(3). go forth and call your init(), queen π§π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms