1

在 Apache 模块中序列化简单类“A”没有错误,但是当我尝试序列化我的复杂对象(如具有成员类型“A”的“X”)时,我在 Apache 模块中遇到了段错误。(这不会发生在可执行的控制台应用程序上)

------------------------- 这是我的代码:-------------------- -

class A {
private:
    friend class boost::serialization::access; // to enable boost "access" class to call private "serialize" method of class "A"
    template<class ArchT>
    void serialize(ArchT &ar, unsigned int version) {   // method for both serializing and deserializing
        ar & memA; // (de)serialize member "memA"
    }
    std::string memA; // sample member
public:
    A(){}
    A(std::string pmemA) :
        memA(pmemA) {
    }
    std::string GetMemA()
    {
        return memA;
    }
};
class X {

private:
    friend class boost::serialization::access;
    template<class ArchT>
    void serialize(ArchT &ar, unsigned int version) {
        ar & memX;
        ar & a;
    }
    std::string memX;
    A a;
public:
    X(std::string pmemX, A pa) :
        memX(pmemX), a(pa) {
    }
    X(){}

};
-------------------
                        string st=GetRandomFileName();
            ofstream out(st.c_str());
            boost::archive::text_oarchive out_r(out);
            A a("Amem");
            X x("Xmem", a);
            out_r << x; // not works
                        out_r << a; // works!

-------------------这是来自gdb for apache的堆栈跟踪----------------

boost::serialization::typeid_system::extended_type_info_typeid_0::is_less_than(boost::serialization::extended_type_info const&) const () from /tmp/libIRSProWebApacheModule.so

2 0xb7223c61 在 std::_Rb_tree
4

0 回答 0