I've been looking at the C++ quick-start guide for msgpack.
http://wiki.msgpack.org/pages/viewpage.action?pageId=1081387
There, there is the following code snippet:
#include <msgpack.hpp>
#include <vector>
#include <string>
class myclass {
private:
std::string str1;
std::string str2;
public:
MSGPACK_DEFINE(str1,str2);
};
int main(void) {
std::vector<myclass> 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(&msg, sbuf.data(), sbuf.size());
msgpack::object obj = msg.get();
// you can convert object to myclass directly
std::vector<myclass> rvec;
obj.convert(&rvec);
}
I want to serialize a vector of myclass objects.
I've tried the following:
...
vector<myclass> rb;
myclass mc;
...
int main(){
...
mc("hello","world");
rb.push_back(mc)
...
}
But this doesn't work ("error: no match for call")
also, if I do:
mc.str1="hello"
mc.str2="world"
it won't work as str1 and str2 are private.
How to use this MSGPACK_DEFINE(...) macro properly? I can't seem to find anything online.
Many thanks,