title: C++ Abstract class operator overloading and interface enforcement question
body: <p>(edited from original post to change "BaseMessage" to "const BaseMessage&amp;")</p>
  
  <p>Hello All,
  I'm very new to C++, so I hope you folks can help me "see the errors of my ways".</p>
  
  <p>I have a hierarchy of messages, and I'm trying to use an abstract base class to enforce 
  an interface.  In particular, I want to force each derived message to provide an overloaded
  &lt;&lt; operator.</p>
  
  <p>When I try doing this with something like this:</p>
  
  <pre><code>class BaseMessage
  {
  public:
  
  // some non-pure virtual function declarations
  // some pure virtual function declarations
  
  virtual ostream&amp; operator&lt;&lt;(ostream&amp; stream, const BaseMessage&amp; objectArg) = 0;
  
  }
  </code></pre>
  
  <p>the compiler complains that </p>
  
  <p>"error: cannot declare parameter ‘objectArg’ to be of abstract type ‘BaseMessage’</p>
  
  <p>I believe there are also "friend" issues involved here, but when I tried to declare it as:</p>
  
  <p><code>virtual friend ostream&amp; operator&lt;&lt;(ostream&amp; stream, const BaseMessage objectArg) = 0;</code></p>
  
  <p>the compiler added an addition error</p>
  
  <p>"error: virtual functions cannot be friends"</p>
  
  <p>Is there a way to ensure that all of my derived (message) classes provide an "&lt;&lt;" ostream operator?</p>
  
  <p>Thanks Much,</p>
  
  <p>Steve</p>