这段代码必须在我们每次创建类时写入,即从template<class archive>
到ar
& BOOST_SERIALIZATION_NVP(b)
。我们怎样才能缩短它? 以及我们如何序列化stl容器?使用boost序列化来序列化类而不更改类
class Employee
{
private:
friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar,
const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(a);
ar & BOOST_SERIALIZATION_NVP(b);
}
int a;
int b;
public:
Employee(int a, int b)
{
this->a = a;
this->b = b;
}
};
的可能重复[我们可以在不同的分离主序列化方法类型的通用包装类使更容易和更简单的使用boost库C++?](http://stackoverflow.com/questions/22603039/can-we-separate-the-main-serialize-method-in-different-class-to-让它更容易a) – jfly