chb*_*er0 5 c++ boost boost-serialization
编译Boost序列化的简单测试时:
class Test
{
protected:
int Num;
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(Num);
}
public:
Test(): Num(0) {}
~Test() {}
};
Run Code Online (Sandbox Code Playgroud)
使用xml_oarchive输出,我遇到以下GCC错误:
C:\Development\Libraries\boost_1_55_0\boost\mpl\assert.hpp|289|error: no matching function for call to 'assertion_failed(mpl_::failed************ boost::serialization::is_wrapper<Test>::************)'|
Run Code Online (Sandbox Code Playgroud)
使用其他oarchive类型时,它编译并运行正常.我所做的所有研究都指出我使用BOOST_SERIALIZATION_NVP宏来解决错误,但我已经这样做了,我仍然得到这个错误.
有没有人遇到过同样的问题?
小智 7
如boost序列化的源代码中所述:
// Anything not an attribute and not a name-value pair is an
// error and should be trapped here.
template<class T>
void save_override(T & t, BOOST_PFTO int)
{
// If your program fails to compile here, its most likely due to
// not specifying an nvp wrapper around the variable to
// be serialized.
BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
this->detail_common_oarchive::save_override(t, 0);
}
Run Code Online (Sandbox Code Playgroud)
您可能不会将它与Test对象一起使用:
Test test;
ar << BOOST_SERIALIZATION_NVP(test);
Run Code Online (Sandbox Code Playgroud)