0

I am referring this : https://theboostcpplibraries.com/boost.serialization-class-hierarchies

I want to serialize object of my class, to std::vector<unsigned char>

class Person {
  int id;
  std::string name;
}

And then deserialize back to that class.

But I do not completely understand the implementation in the above URL. Can anybody help?

user17836
  • 103
  • 1
  • 7

1 Answers1

0

In such case it is best to see original documentation. Blogs are often written by people who are in learning stage so in most cases they are not trustworthy (I don't say this is the case, but you should have limited trust to blogs written by someone you do not known).

The whole trick here is template method void serialize(Archive & ar, const unsigned int version). Since it is a template once it is used to serialize and once to deserialize data.

Since code is doing writing and reading at the same time, stream operators << >> can't be used. Authors of library decided to use bit wise and operator & to express that it can do a reading and writing. It looks strange like definition of a reference, but note on left side you have argument of method and or right side you have a field name.

Marek R
  • 32,568
  • 6
  • 55
  • 140