Extending serialization using a private constructor works in 1.57 not in 1.58

Under certain circumstances, deserializing a class with a private constructor does not work with Boost 1.58. At 1.57, it worked fine. The following error message appears in the code below when compiling with Visual Studio 2013.

error message:

1> SerializeTest.cpp 1>c:\program files (x86)\vc\include\xmemory0(588): error C2248: 'A::A' : cannot access private member declared in class 'A' 1> c:\projects\serializetest\serializetest.cpp(14) : see declaration of 'A::A' 1> c:\projects\serializetest\serializetest.cpp(9) : see declaration of 'A' 

the code:

 #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/serialization/serialization.hpp> #include <boost/serialization/vector.hpp> #include <vector> #include <sstream> class A { public: A(int i) {} private: A() {} friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int version) { } }; class B { public: B() {} private: std::vector<A> m_a; friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(m_a); } }; int main(int argc, char* argv[]) { std::ostringstream os; boost::archive::text_oarchive oa(os); { B b; oa & b; } { std::stringstream myIstream; myIstream.write(os.str().c_str(), os.str().length()); boost::archive::text_iarchive ia(myIstream); B b; ia >> b; } return 0; } 

Is this a Boost regression or a supervision with me?

+7
boost serialization
source share
1 answer

I had the same problem, look in the xmemory header! For me, the error appeared in std :: allocator, so I needed to add something like

 friend class std::allocator<A>; 

in addition to the friends class for serialization!

0
source share

All Articles