title: Object returned from lambda loses property value
body: <p>I am taking a course that is several years old so learning how to use serialization for the first time.</p>
  
  <p>When the "return result" executes in the lambda, the Address property of the Contact becomes uninitialized.  The commented out code works just fine so I am fairly sure that I compiled the Boost libraries ok.  </p>
  
  <p>The name on the Contact comes back ok.  Why doesn't the Address?</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;functional&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  #include &lt;boost/serialization/serialization.hpp&gt;
  #include &lt;boost/archive/text_iarchive.hpp&gt;
  #include &lt;boost/archive/text_oarchive.hpp&gt;
  
  struct Address
  {
  public:
      string street, city;
      int suite;
  
      Address() {};
      Address(string street, string city, int suite)
          : suite(suite),street(street),city(city){ }
  
    friend ostream&amp; operator&lt;&lt;(ostream&amp; os, const Address&amp; obj)
    {
      return os
        &lt;&lt; "street: " &lt;&lt; obj.street
        &lt;&lt; " city: " &lt;&lt; obj.city
        &lt;&lt; " suite: " &lt;&lt; obj.suite;
    }
  
  private:
    friend class boost::serialization::access;
  
    template&lt;class Ar&gt; void serialize(Ar&amp; ar, const unsigned int version)
    {
      ar &amp; street;
      ar &amp; city; 
      ar &amp; suite;
    }
  };
  
  struct Contact
  {
    string name;
    Address* address;
  
  
    friend ostream&amp; operator&lt;&lt;(ostream&amp; os, const Contact&amp; obj)
    {
      return os
        &lt;&lt; "name: " &lt;&lt; obj.name
        &lt;&lt; " address: " &lt;&lt; *obj.address;
    }
  private:
    friend class boost::serialization::access;
  
    template&lt;class Ar&gt; void serialize(Ar&amp; ar, const unsigned int version)
    {
      ar &amp; name;
      ar &amp; address;
    }
  };
  
  int main()
  {
    Contact john;
    john.name = "John Doe";
    john.address = new Address{ "123 East Dr", "London", 123 };
  
    auto clone = [](Contact c)
    {
      ostringstream oss;
      boost::archive::text_oarchive oa(oss);
      oa &lt;&lt; c;
  
      string s = oss.str();
  
      Contact result;
      istringstream iss(s);
      boost::archive::text_iarchive ia(iss);
      ia &gt;&gt; result;
      return result;
    };
  
    // This works fine
    //ostringstream oss;
    //boost::archive::text_oarchive oa(oss);
    //oa &lt;&lt; john;
  
    //string s = oss.str();
  
    //Contact newJane;
    //{
       // istringstream iss(s);
       // boost::archive::text_iarchive ia(iss);
       // ia &gt;&gt; newJane;
    //}
  
    //newJane.name = "Jane";
    //newJane.address-&gt;street = "123B West Dr";
  
    //cout &lt;&lt; john &lt;&lt; endl &lt;&lt; newJane &lt;&lt; endl;
  
  
    Contact jane = clone(john);
    jane.name = "Jane";
    jane.address-&gt;street = "123B West Dr";
  
    cout &lt;&lt; john &lt;&lt; endl &lt;&lt; jane &lt;&lt; endl;
  
    getchar();
    return 0;
  }
  </code></pre>