1

嗨,我正在使用 boost/1.41.0,当我尝试反序列化 shared_ptr 时,以下代码给了我编译错误。它编译成功的序列化部分。如果这是我的代码中的错误或提升的一般问题,有人可以告诉我吗?谢谢。

燕超

#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;
} 
4

0 回答 0