title: "unregistered void cast" using boost serialiazation derived to base class
body: <p>I am on my second attempt to setup polymorphic serialization using the boost library.  I am using this as a learning experience, but I may be a little in over my head and I am considering going back to coding the serialization myself rather than boost. Or switch to learning the vistor message Sehe showed me in a previous post. </p>
  
  <p>The issue I am seeing is "unregistered void cast"</p>
  
  <p>I am using shared library linking for the boost serialization library</p>
  
  <p>aTodo.h:</p>
  
  <pre><code>#ifndef ATODO_H
  #define ATODO_H
  #include &lt;boost/serialization/export.hpp&gt;
  #include &lt;boost/archive/text_iarchive.hpp&gt;
  #include &lt;boost/archive/text_oarchive.hpp&gt;
  #include &lt;boost/serialization/unique_ptr.hpp&gt;
  
  #include &lt;boost/iostreams/device/back_inserter.hpp&gt;
  #include &lt;boost/iostreams/device/array.hpp&gt;
  #include &lt;boost/iostreams/stream.hpp&gt;
  
  class aTodo{
    public: 
     static const unsigned _Type=0x00;
     virtual ~aTodo(){};
     virtual void Do()=0;
     virtual unsigned getInitType(){return _Type;};
  
     private:
     friend class boost::serialization::access;
     template  &lt;class Ar&gt; void serialize(Ar &amp;, unsigned){};
  };
  #endif
  </code></pre>
  
  <p>todoExec.h:</p>
  
  <pre><code> #ifndef ATODOEXEC_H
  #define ATODOEXEC_H
  #include "aTodo.h"
  class todoExec : public aTodo{
     public:
     static const unsigned _TYPE= 0x01;
        todoExec(std::string const &amp; command=""):_command(command){};
        virtual unsigned getInitType(){return  _TYPE;};
        virtual void Do(){std::cout &lt;&lt; "foo:" &lt;&lt; getCommand() &lt;&lt; std::endl;};
        std::string getCommand() const {return _command;};
     protected:
  
     private: 
        friend class boost::serialization::access;
        template &lt;class Archive&gt; void serilize(Archive &amp; ar, unsigned){
           boost::serialization::void_cast_register&lt;todoExec,aTodo&gt;();
           boost::serialization::base_object&lt;aTodo&gt;(*this);
           ar&amp; _command;
        }  
     std::string _command;
  };
  #endif
  </code></pre>
  
  <p>todoFactory.h:</p>
  
  <pre><code>#ifndef TODOFACTORY_H
  #define TODOFACTORY_H
  
  #include "todoExec.h"
  #include &lt;memory&gt;
  class todoFactory{
  
      todoFactory()=default;
     public:
        static std::unique_ptr&lt;todoFactory&gt; create(){return std::move(std::unique_ptr&lt;todoFactory&gt;(new todoFactory));};
  
        //save
        static std::string save(std::unique_ptr&lt;aTodo&gt; &amp;todoIn){
           std::string out;
           {  
              boost::iostreams::stream&lt;boost::iostreams::back_insert_device&lt;std::string&gt;&gt;os(out);
              boost::archive::text_oarchive archive(os);
  
              archive &lt;&lt; todoIn;
           }  
           return out;
  
        }  
  
        static std::unique_ptr&lt;aTodo&gt; load(std::string const &amp;s ){ 
           std::unique_ptr&lt;aTodo&gt; p; 
           {  
              boost::iostreams::stream&lt;boost::iostreams::array_source&gt; is(boost::iostreams::array_source{s.data(),s.size()});
              boost::archive::text_iarchive archive(is);
              archive &gt;&gt; p; 
           }  
           return std::move(p);
         }  
         std::unique_ptr&lt;aTodo&gt; createExec(std::string command) {return std::unique_ptr&lt;aTodo&gt;(new todoExec(command));};
  
  };
  #endif
  </code></pre>
  
  <p>client.cpp</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include "todoFactory.h"
  BOOST_SERIALIZATION_ASSUME_ABSTRACT(aTodo)
  BOOST_CLASS_EXPORT(todoExec)
  
  
  #include &lt;memory&gt;
  
  int main(void)
  {
    char mtype=0x01;
     std::string dataToSend = "ls -al /home/ajonen";
  
     auto tmpTodoFactory=todoFactory::create(); //create factory
     auto anExecTodo=tmpTodoFactory-&gt;createExec(dataToSend); //create ExecTodo from factory
     std::string toSend= tmpTodoFactory-&gt;save(anExecTodo);
    return 0;
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>terminate called after throwing an instance of 'boost::archive::archive_exception'
    what():  unregistered void cast 8todoExec&lt;-5aTodo
  Aborted
  </code></pre>