title: C++ Boost deserialization what(): input stream error
body: <p>I'm trying to make a serialization of an object and then to deserialize it. Even though it seems that everything I wrote is ok I'm still getting an error during the deserialization.</p>
  
  <pre><code>int main(){
  
  MapAttributes mapAtt(MAP_SIZE,MAP_SIZE);
  
  initMapFromImage("map1.png",&amp;mapAtt);
  
  
  int prevxMax = mapAtt.prevxMax ;
  int prevyMax = mapAtt.prevyMax ;
  int prevxMin = mapAtt.prevxMin ;
  int prevyMin = mapAtt.prevyMin ;
  
  
  PixelCoords pose = PixelCoords(mapAtt.robotPose.dx, mapAtt.robotPose.dy);
  PixelCoords target = PixelCoords( 2048+250, 2048+250 );
  
  
  PartitionGraphNodes partitionGraph(&amp;mapAtt);
  PartitionGraphNodes partitionGraph2(&amp;mapAtt);
  partitionGraph.createIncrementalPartition(pose,target);
  
  if (partitionGraph.nodes.size()!=0){
      saveSerializedObject&lt;PartitionGraphNodes(partitionGraph,"partition_graph_marshall");
  
      std::cout &lt;&lt; "size= " &lt;&lt; partitionGraph.nodes.size() &lt;&lt; "\n";
      restoreSerializedObject&lt;PartitionGraphNodes&gt;(partitionGraph2,"partition_graph_marshall");
  
  }
  else{
  
      std::cout &lt;&lt; "RUN FOR YOUR LIVES!!!\n";
  }
  return 0;
  </code></pre>
  
  <p>This is my code where I'm trying to get my objects serialized and deserialized.</p>
  
  <p>Here is the function for the serialization and the deserialization:</p>
  
  <pre><code>template&lt;class T&gt;
  void saveSerializedObject(const T &amp;s, const char * filename){
  // make an archive
  std::ofstream ofs(filename);
  boost::archive::text_oarchive oa(ofs);
  oa &lt;&lt; s;
  }
  
  
  template&lt;class T&gt;
  void restoreSerializedObject(T &amp;s, const char * filename)
  {
      // open the archive
  
      std::ifstream ifs(filename);
      if (ifs.good()) {
  
      std::cout &lt;&lt; "Coming!!!\n";
              boost::archive::text_iarchive ia(ifs);
              ia &gt;&gt; s;
      } else {
              // throw an error or something
              assert(false);
      }
  
   }
  </code></pre>
  
  <p>Finally I have wrote the code for the serialization exactly as the Boost documentation suggests, but I still get an error: an instance of 'boost::archive::archive_exception' what():  input stream error. Can you help me with that? </p>
  
  <p>EDIT:</p>
  
  <p>As it is clear enough, initially I'm trying to serialize an object of class PartitionGraphNodes. So this is how an PartitionGraphNodes object is serialized:</p>
  
  <pre><code>#include &lt;boost/serialization/base_object.hpp&gt;
   class PartitionGraphNodes: public NodesVector{
  
  private:
      std::vector&lt;int&gt; targetNeighbors;           //!&lt;Vector holding target neighbors
  
  std::vector&lt;int&gt; robotNeighbors;            //!&lt;Vector holding robot neighbors  
  std::vector&lt;PixelCoords&gt; uniformPartition;
  
  public:
  
  PartitionGraphNodes(MapAttributes* mapAttr);    
  void createIncrementalPartition(PixelCoords startPos, PixelCoords target);      
  int insertNodeInPartition(Node currNode);
  
  
  
  template&lt;class Archive&gt;
  void serialize(Archive &amp; ar, const unsigned int version)
  {
      // serialize base class information
      std::cout &lt;&lt; "In partition_serial" &lt;&lt; "\n";
      ar &amp; boost::serialization::base_object&lt;NodesVector&gt;(*this);
  }
  };
  
  #include &lt;boost/serialization/vector.hpp&gt;
  class NodesVector{
  
  protected:
  
      //~ std::vector&lt;Voronode&gt; nodes;
  
  public:
  
      NodesVector(void){};
      std::vector&lt;Node&gt; nodes;
      MapAttributes* mapAttributes;
  
      template&lt;class Archive&gt;
      void serialize(Archive &amp; ar, const unsigned int version)
      {
              std::cout &lt;&lt; "In nodesVector_serial" &lt;&lt; "\n";
              ar &amp; nodes;
      }
  
  };
  
  
  #include &lt;boost/serialization/vector.hpp&gt;
  class Node{
  
  public:
  
  PixelCoords p;                      //!&lt; The coordinates of the node
  bool visited;                       //!&lt; True if the node has been visited
  unsigned int ID;                    //!&lt; The node's ID
  int parent;
  
  std::vector&lt;PixelCoords&gt; neigh;     //!&lt; Vector of the neighbors of the node (coords)
  std::vector&lt;unsigned int&gt; neighID;  //!&lt; Vector of the neighbors' IDs
  std::vector&lt;float&gt; dist;            //!&lt; Vector of the distances of the neighbors
  
  Weight w;                           //!&lt; The node's weight
  
  std::vector&lt;PixelCoords&gt; path;
  
  Node(PixelCoords a) {p=a;}   
  Node(PixelCoords a,unsigned int IDt) {p=a; ID=IDt;}
  Node(void){}           
  
  void makeNeighbor(Node &amp;a);     
  
  
  template&lt;class Archive&gt;
  void serialize(Archive &amp; ar, const unsigned int version)
  {
          std::cout &lt;&lt; "In nodes_serial" &lt;&lt; "\n";
          ar &amp; p;
          ar &amp; visited;
          ar &amp; ID;
          ar &amp; parent;
          ar &amp; neigh;
          ar &amp; neighID;
          ar &amp; dist;
          ar &amp; w;
  }
  
  
  };
  
  #endif
  </code></pre>