title: boost serialization exception: unregistered class, serializing polymorphic base problem
body: <p>i've been reading, cross-referencing, and ultimately not finding a coherent example and answer. what i'm trying to do is pretty simple, but i'm clearly missing something. in english, i've got a class structure with two abstract bases (pure BB derives from pure AA), which i manage as a:</p>
  
  <pre><code>std::vector&lt;AA*&gt;
  </code></pre>
  
  <p>i'd like to serialize another object containing this vector. everything <em>except</em> this vector serializes fine, but once it gets to the vector, it throws:</p>
  
  <pre><code>terminate called after throwing an instance of 'boost::archive::archive_exception'
    what():  unregistered class - derived class not registered or exported
  </code></pre>
  
  <p>i've tried a few things, including explicitly registering the parent types prior to serialization, expressly declaring the base abstract classes as such with 'BOOST_SERIALIZATION_ASSUME_ABSTRACT', etc. however, i'm left with the exception at runtime.</p>
  
  <p>i'd like to get this example (and solution) on the record so others can use this excellent, if a little opaque, library. once this example is square, i'll submit it to the boost serialization maintainers to include in either the FAQ or documentation as they see fit.</p>
  
  <p>sample code to replicate the problem below:</p>
  
  <pre><code>/*
      g++ -Iinclude/ -Llib -lboost_serialization ~/Desktop/ser_ex.cpp -o stest
  */
  #include &lt;boost/serialization/serialization.hpp&gt;
  #include &lt;boost/serialization/nvp.hpp&gt;
  #include &lt;boost/archive/xml_oarchive.hpp&gt;
  #include &lt;boost/serialization/vector.hpp&gt;
  
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  namespace bser = boost::serialization;
  class AA
  {
  public:
      virtual void foo() = 0;
      std::string name;
  
      template&lt;class Archive&gt;
      void serialize(Archive &amp; ar, unsigned int file_version)
      {
          ar &amp; bser::make_nvp( "Name", name );
      }
  };
  BOOST_SERIALIZATION_ASSUME_ABSTRACT( AA );
  
  class BB : public AA
  {
  public:
      virtual void foo() = 0;
      virtual void bar() = 0;
      int thing;
  
      template&lt;class Archive&gt;
      void serialize(Archive &amp; ar, unsigned int file_version)
      {
          ar.template register_type&lt; AA &gt;();
          ar &amp; bser::base_object&lt; AA &gt;( *this );
          ar &amp; bser::make_nvp( "Thing", thing );
      }
  };
  BOOST_SERIALIZATION_ASSUME_ABSTRACT( BB );
  
  class CC : public BB
  {
  public:
      virtual void foo() {}
      virtual void bar() {}
      int otherThing;
  
      template&lt;class Archive&gt;
      void serialize(Archive &amp; ar, unsigned int file_version)
      {
          ar.template register_type&lt; BB &gt;();
          ar &amp; bser::base_object&lt; BB &gt;( *this );
          ar &amp; bser::make_nvp( "OtherThing", otherThing );
      }
  };
  
  int main (int argc, char const *argv[])
  {
      const std::string filename( "my.serialized" );
      const std::string key( "AAVector" );
  
      std::vector&lt; AA* &gt; vv;
      vv.push_back( new CC );
  
      std::ofstream outfilestream( filename.c_str(), std::ios::binary );
      boost::archive::xml_oarchive out_archive( outfilestream );
      out_archive &lt;&lt; boost::serialization::make_nvp( key.c_str(), vv );
      outfilestream.close();
  }
  </code></pre>