Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that ostream does not clean up the stream buffer in its destructor:</p> <p><a href="http://www.cplusplus.com/reference/iostream/ostream/~ostream/" rel="nofollow">http://www.cplusplus.com/reference/iostream/ostream/~ostream/</a></p> <blockquote> <p>[...] Note that it does not destroy nor performs any operations on the associated streambuf object.</p> </blockquote> <p>So you have to clean up the streambuf somewhere else. The easiest thing is to make your stampbuf object a member variable of stampstream - then its destructor gets called automatically when your stampstream is destructed.</p> <p>The constructor of the base class ostream gets called before member variables get constructed, so the constructor of ostream ends up looking at an unconstructed stampbuf object if you pass the stampbuf object as a parameter to the ostream constructor. So instead do not pass the stream buffer to the constructor, set it inside the constructor, after the stampbuf has been construct using rdbuf:</p> <p><a href="http://www.cplusplus.com/reference/iostream/ios/rdbuf/" rel="nofollow">http://www.cplusplus.com/reference/iostream/ios/rdbuf/</a></p> <p>This presents the problem that your stampbuf gets destructed before the base class does, so the destructor of ostream is going to be looking at a deconstructed stampbuf. That is normally unacceptable, but since the page for ~ostream above guarantees that ~ostream does not do anything with the stream buffer, it is fine in this case. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload