title: How do I make boost::serialization work with std::shared_ptr?
body: <p>This question has been <a href="https://stackoverflow.com/questions/12835780/visual-studio-2012-error-c2039-serialize-is-not-a-member-of-stdshared-pt">asked here</a> and a few other places but the answers don't really seem to address the latest Boost library.</p>
  <p>To illustrate the issue, suppose we want to serialize a class containing a shared pointer (<code>std::shared_ptr</code>), along with a static <code>load</code> function that will build the class from a file and a <code>save</code> function that will store the instance to a file:</p>
  <pre><code>#include &lt;boost/archive/text_iarchive.hpp&gt;
  #include &lt;boost/archive/text_oarchive.hpp&gt;
  #include &lt;boost/serialization/shared_ptr.hpp&gt;
  
  #include &lt;fstream&gt;
  #include &lt;memory&gt;
  #include &lt;vector&gt;
  
  class A
  {
  public:
      std::shared_ptr&lt;int&gt; v;
  
      void A::Save(char * const filename);
      static A * const Load(char * const filename);
  
          //////////////////////////////////
          // Boost Serialization:
          //
      private:
          friend class boost::serialization::access;
          template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int file_version) 
          {
              ar &amp; v;
          }
  };
  
  // save the world to a file:
  void A::Save(char * const filename)
  {
      // create and open a character archive for output
      std::ofstream ofs(filename);
  
      // save data to archive
      {
          boost::archive::text_oarchive oa(ofs);
  
          // write the pointer to file
          oa &lt;&lt; this;
      }
  }
  
  // load world from file
  A * const A::Load(char * const filename)
  {
      A * a;
  
      // create and open an archive for input
      std::ifstream ifs(filename);
  
      boost::archive::text_iarchive ia(ifs);
  
      // read class pointer from archive
      ia &gt;&gt; a;
  
      return a;
  }
  
  int main()
  {
  
  }
  </code></pre>
  <p>The above code generates a long list of errors starting with <code>c:\local\boost_1_54_0\boost\serialization\access.hpp(118): error C2039: 'serialize' : is not a member of 'std::shared_ptr&lt;_Ty&gt;'</code>, which as far as I understand shouldn't be true given that I have loaded the boost <code>shared_ptr</code> serialization library which ostensibly supports <code>std::shared_ptr</code>. What am I missing here?</p>
  <p><strong>NOTE: As far as I understand, my assumption that <code>boost/serialization/shared_ptr.hpp</code> defined a <code>serialize</code> function for <code>std::shared_ptr</code> was wrong, hence the correct answer to this question is probably that I'd either have to define my own <code>serialize</code> functions for <code>std::shared_ptr</code> or convert to <code>boost::shared_ptr</code></strong></p>