title: How to deserialize a vector of pairs and objects using boost c++
body: <p>I am having a problem in deserialization using boost library.</p>
  <hr />
  <h1>Serialization process:</h1>
  <p>The serialization process is based on <a href="https://stackoverflow.com/questions/978311/c-boost-ptr-map-serialization-error">How can I serialize an std::vector with boost::serialization</a></p>
  <ul>
  <li>The vector that i want to serialize is the following: <code>vector&lt;pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, string &gt;&gt;</code></li>
  <li>I have no problem with the serialization process</li>
  <li>The problem is with the deserialization process</li>
  </ul>
  <hr />
  <h1>compiler log</h1>
  <pre><code>||=== Build: Debug in EntityLinking (compiler: GNU GCC Compiler) ===|
  
  - access.hpp||In instantiation of ‘static void boost::serialization::access::construct(T*) [with T = QueryEntity]’:|
  - serialization.hpp|93|required from ‘void boost::serialization::load_construct_data(Archive&amp;, T*, unsigned int) [with Archive = boost::archive::text_iarchive; T = QueryEntity]’|
  - serialization.hpp|158|required from ‘void boost::serialization::load_construct_data_adl(Archive&amp;, T*, unsigned int) [with Archive = boost::archive::text_iarchive; T = QueryEntity]’|
  - iserializer.hpp|323|required from ‘void boost::archive::detail::pointer_iserializer&lt;Archive, T&gt;::load_object_ptr(boost::archive::detail::basic_iarchive&amp;, void*&amp;, unsigned int) const [with Archive = boost::archive::text_iarchive; T = QueryEntity]’|
  - iserializer.hpp|203|required from ‘class boost::archive::detail::pointer_iserializer&lt;boost::archive::text_iarchive, QueryEntity&gt;’|
  - interface_iarchive.hpp|54|required from ‘const boost::archive::detail::basic_pointer_iserializer* boost::archive::detail::interface_iarchive&lt;Archive&gt;::register_type(T*) [with T = QueryEntity; Archive = boost::archive::text_iarchive]’|
  - iserializer.hpp|459|  [ skipping 92 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]|
  - common_iarchive.hpp|66|required from ‘void boost::archive::detail::common_iarchive&lt;Archive&gt;::load_override(T&amp;, int) [with T = std::vector&lt;std::pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, std::basic_string&lt;char&gt; &gt; &gt;; Archive = boost::archive::text_iarchive]’|
  - basic_text_iarchive.hpp|65|required from ‘void boost::archive::basic_text_iarchive&lt;Archive&gt;::load_override(T&amp;, int) [with T = std::vector&lt;std::pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, std::basic_string&lt;char&gt; &gt; &gt;; Archive = boost::archive::text_iarchive]’|
  - text_iarchive.hpp|82|required from ‘void boost::archive::text_iarchive_impl&lt;Archive&gt;::load_override(T&amp;, int) [with T = std::vector&lt;std::pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, std::basic_string&lt;char&gt; &gt; &gt;; Archive = boost::archive::text_iarchive]’|
  - interface_iarchive.hpp|60|required from ‘Archive&amp; boost::archive::detail::interface_iarchive&lt;Archive&gt;::operator&gt;&gt;(T&amp;) [with T = std::vector&lt;std::pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, std::basic_string&lt;char&gt; &gt; &gt;; Archive = boost::archive::text_iarchive]’|
  - interface_iarchive.hpp|67|required from ‘Archive&amp; boost::archive::detail::interface_iarchive&lt;Archive&gt;::operator&amp;(T&amp;) [with T = std::vector&lt;std::pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, std::basic_string&lt;char&gt; &gt; &gt;; Archive = boost::archive::text_iarchive]’|
  </code></pre>
  <p><strong>main.cpp|49|required from here|</strong></p>
  <pre><code>- access.hpp|132|error: no matching function for call to ‘QueryEntity::QueryEntity()’|
  - access.hpp|132|note: candidates are:|
  - QueryEntity.h|28|note: QueryEntity::QueryEntity(const string&amp;, const string&amp;, std::vector&lt;std::basic_string&lt;char&gt; &gt;&amp;)|
  - QueryEntity.h|28|note:   candidate expects 3 arguments, 0 provided|
  - QueryEntity.h|15|note: QueryEntity::QueryEntity(const QueryEntity&amp;)|
  - QueryEntity.h|15|note:   candidate expects 1 argument, 0 provided|
  - QueryEntity.h|15|note: QueryEntity::QueryEntity(QueryEntity&amp;&amp;)|
  - QueryEntity.h|15|note:   candidate expects 1 argument, 0 provided|
  </code></pre>
  <hr />
  <h1>main.cpp</h1>
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;fstream&gt;
      
      // include input and output archivers
      #include &lt;boost/archive/text_oarchive.hpp&gt;
      #include &lt;boost/archive/text_iarchive.hpp&gt;
      #include &lt;boost/serialization/vector.hpp&gt;
      //serialize shared_ptr
      #include &lt;boost/serialization/shared_ptr.hpp&gt;
      //serialize pair
      #include &lt;boost/serialization/utility.hpp&gt;
      
      #include &quot;query/LoadQuery.h&quot;
      using namespace std;
      
      int main()
      {
      
              LoadQuery lq(&quot;list_queries.txt&quot;);
              vector&lt;pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, string &gt;&gt; queries = lq.createQuerties()
          //serialization
              {
                  ofstream ofs(&quot;variations.var&quot;);
                  boost::archive::text_oarchive oa(ofs);
                  oa &amp; queries;
              }
        vector&lt;pair&lt;boost::shared_ptr&lt;QueryEntity&gt;, string &gt;&gt; variations;
         {
           std::ifstream ifs(&quot;variations.var&quot;);
           boost::archive::text_iarchive ia(ifs);
           ia &amp; variations;
         }
      return 0;
      }
  </code></pre>
  <hr />
  <h1>QUERYENTITY</h1>
  <pre><code>#ifndef QUERYENTITY_H
  #define QUERYENTITY_H
  
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  #include &lt;boost/archive/binary_oarchive.hpp&gt;
  #include &lt;boost/archive/binary_iarchive.hpp&gt;
  #include &lt;boost/serialization/vector.hpp&gt;
  
  using namespace std;
  
  class QueryEntity
  {
  
  public:
      QueryEntity(const string &amp;, const string &amp;, vector&lt;string&gt; &amp;);
      //AFTER CORRECTION by stackoverflow. I had to add a default constructor to the clas
      QueryEntity();
      string getId() const;
      string getDocId() const;
      vector&lt;string&gt; getName() const;
      void setVector(const vector&lt;string&gt; &amp; v);
  private:
      string _id;
      string _docId;
      vector&lt;string&gt; _name;
  friend class boost::serialization::access;
      template&lt;class Archive&gt;
  
      void serialize(Archive &amp; ar, const unsigned int version)
      {
          ar &amp; _id;
          ar &amp; _docId;
          ar &amp; _name;
      }
  
  };
  
  #endif // QUERYENTITY_H
  </code></pre>
  <hr />