在编译 Boost Serialization 的简单测试时:
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() {}
};
使用 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>::************)'|
当使用其他 oarchive 类型时,它编译并运行良好。我所做的所有研究都指向我使用 BOOST_SERIALIZATION_NVP
宏来解决错误,但我已经这样做了,但我仍然遇到此错误。
有人遇到过同样的问题吗?
最佳答案
如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);
}
您可能不会将它与您的测试对象一起使用:
Test test;
ar << BOOST_SERIALIZATION_NVP(test);
关于c++ - 将 Boost 序列化与 xml_oarchive 一起使用时 assertion_failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21508256/