title: C++ msgpack User-defined classes - can't get started
body: <p>I've been looking at the C++ quick-start guide for msgpack.</p>
  
  <p><a href="http://wiki.msgpack.org/pages/viewpage.action?pageId=1081387" rel="nofollow">http://wiki.msgpack.org/pages/viewpage.action?pageId=1081387</a></p>
  
  <p>There, there is the following code snippet:</p>
  
  <pre><code>#include &lt;msgpack.hpp&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  
  class myclass {
  private:
      std::string str1;
      std::string str2;
  public:
      MSGPACK_DEFINE(str1,str2);
  };
  
  int main(void) {
          std::vector&lt;myclass&gt; vec;
          // add some elements into vec...
          /////
          /* But what goes here??? */
          /////
  
          // you can serialize myclass directly
          msgpack::sbuffer sbuf;
          msgpack::pack(sbuf, vec);
  
          msgpack::unpacked msg;
          msgpack::unpack(&amp;msg, sbuf.data(), sbuf.size());
  
          msgpack::object obj = msg.get();
  
          // you can convert object to myclass directly
          std::vector&lt;myclass&gt; rvec;
          obj.convert(&amp;rvec);
  }
  </code></pre>
  
  <p>I want to serialize a vector of myclass objects.</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>...
  vector&lt;myclass&gt; rb;
  myclass mc;
  
  ...
  
  int main(){
      ...
      mc("hello","world");
      rb.push_back(mc)
      ...
  }
  </code></pre>
  
  <p>But this doesn't work ("error: no match for call")</p>
  
  <p>also, if I do:</p>
  
  <pre><code>mc.str1="hello"
  mc.str2="world"
  </code></pre>
  
  <p>it won't work as str1 and str2 are private.</p>
  
  <p>How to use this MSGPACK_DEFINE(...) macro properly? I can't seem to find anything online.</p>
  
  <p>Many thanks,</p>