将Boost序列化与xml_oarchive一起使用时assertion_failed [英] assertion_failed when using Boost Serialization with xml_oarchive
问题描述
在编译Boost序列化的简单测试时:
When compiling a simple test of 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错误:
using an xml_oarchive for output, I am experiencing the following GCC error:
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>::************)'|
使用其他归档类型时,它可以编译并正常运行.我所做的所有研究都指出我要使用BOOST_SERIALIZATION_NVP
宏来解决该错误,但我已经这样做了,但仍然遇到此错误.
When using other oarchive types, it compiles and runs fine. All the research I have done pointed me to using the BOOST_SERIALIZATION_NVP
macro to solve the error, but I am already doing that and I still get this error.
有人遇到过同样的问题吗?
Has anyone experienced this same issue?
推荐答案
如boost序列化的源代码中所述:
As described in the source code of boost serialization:
// 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对象一起使用:
You likely do not use it with your Test object:
Test test;
ar << BOOST_SERIALIZATION_NVP(test);
这篇关于将Boost序列化与xml_oarchive一起使用时assertion_failed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!