title: How to serialize a self-defined class containing a STL container of another self-defined class using boost serialization easily?
body: <p>I have read the tutorial here <a href="http://www.boost.org/doc/libs/1_59_0/libs/serialization/doc/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_59_0/libs/serialization/doc/index.html</a> and googled a lot of pages, but I am still not sure how to do it.</p>
  
  <p>I have read how to serialize a self-defined class and how to serialize a self-defined class containing STL container of std::string or pointers. But I'm not sure how to serialize a self-defined class containing a STL container of another self-defined class using boost serialization easily? Since std::string and pointers are standard C++ types, the boost knows how to deal with them. In case of a STL container of self-defined class, I fell I have to tell boost how to deal with it when serializing. But how? This is my self-defined 2 classes.</p>
  
  <pre><code>class Instance
  {
  public:
      Instance(){}
      ~Instance();
      //... a lot of functions here.
  private:
      InstanceIdentity identity_;
      mutable ClassLabel class_label_;
      mutable FeatureGroup features_;
      friend class InstanceManager;
  };
  
  class InstanceManager
  {
  public:
      InstanceManager(){}
      ~InstanceManager();
      // a lot of functions here.
  private:
      set&lt;Instance&gt; instances_;
  };
  </code></pre>
  
  <p>According to the tutorial part of <a href="http://www.boost.org/doc/libs/1_59_0/libs/serialization/doc/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_59_0/libs/serialization/doc/index.html</a> , since boost knows how to deal with STL container, so what I need to do is add</p>
  
  <pre><code>friend class boost::serialization::access;
  template&lt;class Archive&gt;
  void serialize(Archive &amp; ar, const unsigned int version)
  {
      ar &amp; instances_;
  }
  </code></pre>
  
  <p>in class InstanceManager. And add </p>
  
  <pre><code>friend class boost::serialization::access;
  template&lt;class Archive&gt;
  void serialize(Archive &amp; ar, const unsigned int version)
  {
      // A lot of things like the following example.
      //ar &amp; degrees;
      //ar &amp; minutes;
      //ar &amp; seconds;
  }
  </code></pre>
  
  <p>in class Instance. Is that right? Or there is better ways. It takes much time to test this by coding. So, can anyone tell me the answer?</p>