Re: [Boost-bugs] [Boost C++ Libraries] #1942: Pointers to elements in a std::map are not serilaized correctly

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #1942: Pointers to elements in a std::map are not serilaized correctly
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-05-28 20:22:34


#1942: Pointers to elements in a std::map are not serilaized correctly
-------------------------------------+--------------------------------------
  Reporter: bernhard.maeder_at_[hidden] | Owner: ramey
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: serialization
   Version: Boost 1.35.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------------+--------------------------------------
Comment (by anonymous):

 We have the same problem. When an instance of ClassB is serialized, all
 the saved pointers in map are lost.

 We are using Boost 1.35.0 running on Fedora7(64 bits). gcc version 4.1.2

 #include <string>
 #include <map>

 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/access.hpp>
 #include <boost/serialization/is_abstract.hpp>

 #include <boost/serialization/base_object.hpp>
 #include <boost/serialization/extended_type_info_typeid.hpp>
 #include <boost/serialization/export.hpp>

 #include <boost/serialization/string.hpp>

 #include <boost/mpl/and.hpp>
 #include <boost/serialization/map.hpp>

 using namespace std;
 using namespace boost::serialization;

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


 class B : public A {

 private:

     friend class boost::serialization::access;
     template<class Archive>
     void serialize(Archive & ar, const unsigned int version)
     {
         // serialize base class information
         ar & boost::serialization::base_object<A>(*this);
         ar & value;
         ar & classACollection;
     }

 protected:
     long value;
     std::map<long, ClassA * > classACollection;

 public:
     A();
     virtual ~A();

 }

 BOOST_CLASS_EXPORT(B);

 class classA {

 private:

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

 protected:

     std::map <long, ClassB *> values;

 public:
     ClassA();
     ClassA(ClassA &object);
     virtual ~ClassA();
 }

 class B {

 private:

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

 protected:

     string value;

 public:
     ClassB();
     ClassB(ClassB &object);
     virtual ~ClassB();

 }

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1942#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:57 UTC