使用版本1.49.0的boost序列化版本运行时,以下代码会破坏版本号。
#include <boost/serialization/nvp.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <iostream>
using namespace std;
using namespace boost::archive;
class Nested {
public:
explicit Nested()
: mC()
{ }
explicit Nested(char c)
: mC(c)
{ }
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int)
{
using boost::serialization::make_nvp;
ar & make_nvp("c", mC);
};
private:
char mC;
};
BOOST_CLASS_VERSION(Nested, 0);
int main()
{
Nested n('c');
{
using boost::serialization::make_nvp;
xml_oarchive ar(cout);
ar << make_nvp("Nested", n);
}
return 0;
}
使用版本1.49.0输出:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="9">
<Nested class_id="0" tracking_level="0" version="2057815296">
<c>99</c>
</Nested>
</boost_serialization>
当我使用旧版本运行时,我会按预期获得0版本:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="6">
<Nested class_id="0" tracking_level="0" version="0">
<c>99</c>
</Nested>
</boost_serialization>
我是否遗漏了不同版本的内容?还有其他人经历过这个吗?