title: send and receive serialized classes from a base class
body: <p>My goal is to create a base class that has a method to :
  1. serialize and send to server
  2. read back from server serialized bytes
  3. recreate itself from serialized bytes</p>
  
  <p>This is to avoid having a second class that would serialize, send , read back and recreate the result for your class. </p>
  
  <p>In affect building in the communication for every inheriting class I may need in the future.  Any inheriting classes do not need to create a send/receive method since the base class already has that method.  They would only need to have the <code>void serialize(Ar &amp;, unsigned)</code> method in order for boost to do the serialization.</p>
  
  <p>My question is in the save method below will the <code>archive &lt;&lt; this;</code> save based on the pointer and call archive on the sub class and NOT the base class?</p>
  
  <p>To put it another way: would i need to write a new <code>save()</code> and <code>load()</code> method on a class that inherits from aTodo.h?  This is what I want to avoid.</p>
  
  <p>The base class I have created is called aTodo.h:</p>
  
  <pre><code>#ifndef ATODO_H
  #define ATODO_H
  #include &lt;boost/archive/text_iarchive.hpp&gt;
  #include &lt;boost/archive/text_oarchive.hpp&gt;
  #include &lt;boost/serialization/export.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;
  #include "protocolBaseServer.h"
  #include "memory.h"
  class aTodo{
    public:
     virtual ~aTodo(){};
     virtual void Do()=0;
  
     //used for a client to send and then receive result back
     std::unique_ptr&lt;aTodo&gt;  WriteRead(std::string ip, int port){
  
      protocolBaseServer protoConnection(ip, port);
      std::string objToSendStr = this-&gt;save(); //save to a string
      protoConnection.DoWrite(objToSendStr);//send string off to server; server does some work
      protoConnection.DoRead();  //read back in the result from the server to a string in object protoConnection
      std::string returnedObjectStr= protoConnection.getTotalMessage(); //save the read bytes to a string
      std::unique_ptr&lt;aTodo&gt; objectReturned=this-&gt;load(returnedObjectStr);
      return objectReturned;
     }
  
     private:
  
     friend class boost::serialization::access;
     template  &lt;class Ar&gt;
     void serialize(Ar &amp;, unsigned){};//every class that inherits from aTodo must have a serialize function
  
  //save pointer to this to a string
     std::string save(){
           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; this;
           }
           return out;
     }
  //write aTodo pointer from string
     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);
  
    }
  
  
  };
  #endif
  </code></pre>