Boost logo

Boost Users :

Subject: [Boost-users] Problems with boost serialization/shared_ptr/container
From: Guo, Yanchao (Yanchao.Guo_at_[hidden])
Date: 2010-01-21 05:35:27


Hi I am using boost/1.41.0, and the following code give me compilation
error when I try to deserialize a shared_ptr. The serialize part it
compiled successfully. Can someone advise me if this is a bug in my code
or a general issue for boost? Thanks.

Yanchao

#include <iomanip>
#include <iostream>
#include <cstddef> // NULL
#include <fstream>
#include <string>
#include <list>

#include <cstdio> // remove
#include <boost/config.hpp>
#if defined(BOOST_NO_STDC_NAMESPACE)
namespace std{
    using ::remove;
}
#endif

#include <boost/archive/text_oarchive.hpp> #include
<boost/archive/text_iarchive.hpp> #include <boost/archive/tmpdir.hpp>

#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/map.hpp>

#include <boost/shared_ptr.hpp>

#include <list>
#include <map>
#include <string>
#include <sstream>

class A{
        public:
                A(){}
                virtual ~A(){}

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

BOOST_SERIALIZATION_SHARED_PTR(A)
typedef std::map<std::string, A > MyMap;

BOOST_SERIALIZATION_SHARED_PTR(MyMap )
int main (){
        boost::shared_ptr<std::map<std::string, A> > test_ptr;
        std::string data;
        std::stringstream buffer(data);
        boost::archive::text_iarchive ia(buffer);
        boost::archive::text_oarchive oa(buffer);

        ia >> test_ptr; //compile error
        oa << test_ptr; //this is ok

        return 1;
}

DISCLAIMER: This e-mail message and any attachments are intended solely for the use of the individual or entity to which it is addressed and may contain information that is confidential or legally privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and permanently delete this message and any attachments.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net