chbaker0 chbaker0 - 1 year ago 90
C++ Question

assertion_failed when using Boost Serialization with xml_oarchive

When compiling a simple test of Boost Serialization:

class Test
int Num;

friend class boost::serialization::access;
template <class Archive>
void serialize(Archive & ar, const unsigned int version)

Test(): Num(0) {}
~Test() {}

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>::************)'|

When using other oarchive types, it compiles and runs fine. All the research I have done pointed me to using the
macro to solve the error, but I am already doing that and I still get this error.

Has anyone experienced this same issue?

Answer Source

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);

You likely do not use it with your Test object:

Test test;