title: Error serializing an abstract class with boost
body: <p>I'm trying to serialize my data structures in order to write them to a tcp socket.</p>
  
  <p>So far I found that my problem is the serialization. I even tried to use</p>
  
  <pre class="lang-cpp prettyprint-override"><code>BOOST_SERIALIZATION_ASSUME_ABSTRACT(T)
  </code></pre>
  
  <p>but I can't find any working example similar to my program and how to implement it correctly.</p>
  
  <p>Here are some of the links that I have visited:</p>
  
  <ul>
  <li><a href="http://programmers-blog.com/category/c-c" rel="nofollow noreferrer">http://programmers-blog.com/category/c-c</a>  </li>
  <li><a href="http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase" rel="nofollow noreferrer">http://www.boost.org/doc/libs/1_48_0/libs/serialization/doc/tutorial.html#simplecase</a>  </li>
  <li><a href="http://en.highscore.de/cpp/boost/serialization.html#serialization_class_hierarchies" rel="nofollow noreferrer">http://en.highscore.de/cpp/boost/serialization.html#serialization_class_hierarchies</a>  </li>
  </ul>
  
  <p>My data structures are a little more complicated then this one but let's assume that I have the following structure</p>
  
  <p>Coordinate.h</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;boost\archive\text_iarchive.hpp&gt;
  #include &lt;boost\archive\text_oarchive.hpp&gt;
  
  class Coordinate {
  public:
      Coordinate() {}
      Coordinate(int c) : c(c) {}
      int get(void) { return c; }
      std::string toString(void);
  private:
      int c;
      friend class boost::serialization::access;
      template&lt;typename Archive&gt;
      void serialize(Archive &amp;ar, const unsigned int version) {
          ar &amp; this-&gt;c;
      }
  };
  </code></pre>
  
  <p>Move.h</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class Coordinate;
  
  #include "Coordinate.h"
  
  #include &lt;boost\archive\text_iarchive.hpp&gt;
  #include &lt;boost\archive\text_oarchive.hpp&gt;
  
  class Move {
  public:
      Move() {}
      ~Move() {}
      Coordinate* getCoordinate(void) {return this-&gt;destination; }
      virtual bool isJump(void) = 0;
  protected:
      Coordinate *destination;
  private:
      friend class boost::serialization::access;
      template&lt;typename Archive&gt;
      void serialize(Archive &amp;ar, const unsigned int version) {
          ar &amp; this-&gt;destination;
      }
  };
  </code></pre>
  
  <p>MoveNormal.h</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class Coordinate;
  
  #include "Move.h"
  #include "Coordinate.h"
  
  #include &lt;boost\archive\text_iarchive.hpp&gt;
  #include &lt;boost\archive\text_oarchive.hpp&gt;
  
  class MoveNormal : public Move {
  public:
      MoveNormal() {}
      MoveNormal(Coordinate *destination) { this-&gt;destination = destination; }
      ~MoveNormal() {}
      virtual bool isJump(void);
  private:
      friend class boost::serialization::access;
      template&lt;typename Archive&gt;
      void serialize(Archive &amp;ar, const unsigned int version) {
          ar &amp; boost::serialization::base_object&lt;Move&gt;(*this);
      }
  };
  </code></pre>
  
  <p>The virtual methods are defined in here.</p>
  
  <p>MoveNormal.cpp</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "MoveNormal.h"
  
  bool MoveNormal::isJump(void) {
      return false;
  }
  </code></pre>
  
  <p>My main.cpp looks like this:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "Coordinate.h"
  #include "Move.h"
  #include "MoveNormal.h"
  
  #include &lt;fstream&gt;
  
  #include &lt;boost\archive\text_iarchive.hpp&gt;
  #include &lt;boost\archive\text_oarchive.hpp&gt;
  
  int main(int argc, char *argv[]) {
      Coordinate *c = new Coordinate(10);
      // This runs OK
      /*
      {
          std::ofstream ofs("f.txt");
          boost::archive::text_oarchive oa(ofs);
          oa &lt;&lt; c;
      }
      Coordinate *d;
      {
          std::ifstream ifs("f.txt");
          boost::archive::text_iarchive ia(ifs);
          ia &gt;&gt; d;
      }
      std::cout &lt;&lt; "c.get(): " &lt;&lt; c-&gt;get() &lt;&lt; std::endl;
      std::cout &lt;&lt; "d.get(): " &lt;&lt; d-&gt;get() &lt;&lt; std::endl;
      */
  
      // This is where I get my error
      Move *m  = new MoveNormal(c);
      {
          std::ofstream ofs("f.txt");
          boost::archive::text_oarchive oa(ofs);
          oa &lt;&lt; m;    // Line where the error occurs
      }
      return 0;
  }
  </code></pre>
  
  <p>But when I run the program I get the following error:</p>
  
  <blockquote>
    <p>Unhandled exception at 0x76dbb9bc in Test.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x001df078..</p>
  </blockquote>
  
  <p>I'm using VS2010, and Boost 1.48.0.</p>