c++ - 将 Boost 序列化与 xml_oarchive 一起使用时 assertion_failed

标签 c++ boost boost-serialization

在编译 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/

相关文章:

c++ - 通过 STL 或 Boost 引入虚拟参数

c++ - boost serialization 1.5.5 在遇到 Nan 和 Inf 时崩溃

c++ - 扩展在 if/else 序列中初始化的变量的范围

c++ - vector 范围构造函数如何在下面的类中工作?

c++ - boost::filesystem::remove_all(path) 是如何工作的?

c++ - Boost 序列化给出未定义的类型 'boost::STATIC_ASSERTION_FAILURE'

c++ - Boost 序列化在特定文件大小后抛出 "input stream error"

c++ - 使用 Boost.ASIO 读取时标准输入管道未关闭

c++ - const 类型没有可行的重载 operator[]

c++ - 错误系统:9:错误的文件描述符 (BOOST::FileSystem)