Private base class
template<class charT,
class traits = std::char_traits<charT> >
struct logoutbuf_init
{
private:
logoutbuf<charT, traits> buf_;
public:
logoutbuf<charT, traits>* buf()
{
return &buf_;
}
};
The fact that the stream buffer is not initialised before it is passed to std::basic_ostream's constructor may not cause a problem with your compiler and library but why risk it when there is a simple and straight forward solution? On the other hand, it may fail in a screaming fit immediately. Moving the stream buffer to a private base class which is initialised before std::basic_ostream solves the problem nicely. The initialisation order of base classes is specified as stated in 12.6.2/5.