title: How to inherit from std::ostream?
body: <p>I've been googling around and I just can't find a simple answer to this. And it should be simple, as the STL generally is.</p>
  
  <p>I want to define MyOStream which inherits publicly from std::ostream. Let's say I want to call foo() each time something is written into my stream.</p>
  
  <pre><code>class MyOStream : public ostream {
  public:
    ...
  private:
     void foo() { ... }
  }
  </code></pre>
  
  <p>I understand that the public interface of ostream is non-virtual, so how can it be done?
  I want clients to be able to  use both operator&lt;&lt; and write() and put() on MyOStream and have use the extended ability of my class.</p>