title: Writing polymorphic class data to a file?
body: <p>So I have these classes.  There's one base class, but it has/will have lots and lots of derivatives, and those derivative classes will be able to have derivatives as well.  I'd like to be able to have a function that writes their binary data to a file, but I'm not sure how to do this with lots and lots of derived classes.</p>
  
  <p>I was thinking something along the lines of:</p>
  
  <pre><code>void writeData(ofstream &amp; _fstream)
  {
      _fstream.write()//etc..
  }
  </code></pre>
  
  <p>But then each derived class that implemented this method would have to write all of it's parent class's data, and that would be duplicating a lot of code.</p>
  
  <p>What's the best way to do this without rewriting all of the previously written <code>writeData()</code> code?</p>