struct MyData { std :: string id; std :: string name; boost :: shared_ptr< mydata> MYDATA; 私人: 朋友类boost :: serialization :: access; template< class archive = > void serialize(Archive& ar,const unsigned int version) { ar& id; ar&姓名; ar& MYDATA; } public: MyData(void); MyData( const parameter_strings& parms); virtual~MyData(void); }; } // MyData.cpp文件 MyData :: MyData(无效) $ } MyData ::〜MyData(无效) { } MyData :: MyData(const parameter_strings& parms) { //实施aprt } BOOST_CLASS_EXPORT_IMPLEMENT(MyData); BOOST_CLASS_IMPLEMENTATION(MyData,boost :: serialization :: object_serializable); BOOST_CLASS_TRACKING(MyData,boost :: serialization :: track_selectively);Hi All,I'm trying to serialize shared pointer using boost but it gives error :Error1error C4308: negative integral constant converted to unsigned typec:\users\mydirect\future\lib\boost_1_55_0\boost\mpl\print.hpp511InputSpent more than 2 days on this but no clue.. when i comment line "ar & MyInfo" error does not come so it means surely issue is with shared pointer.. how do i go ahead.Below is the code :// MyData.hpp file struct MyData { std::string id; std::string name; boost::shared_ptr<mydata> Mydata; private: friend class boost::serialization::access; template<class archive=""> void serialize(Archive &ar, const unsigned int version) { ar & id; ar & name; ar & Mydata; } public: MyData(void); MyData(const parameter_strings & parms); virtual ~MyData(void); };}// MyData.cpp fileMyData::MyData(void){}MyData::~MyData(void){}MyData::MyData(const parameter_strings & parms){ // implementation aprt}BOOST_CLASS_EXPORT_IMPLEMENT(MyData); BOOST_CLASS_IMPLEMENTATION(MyData,boost::serialization::object_serializable);BOOST_CLASS_TRACKING(MyData,boost::serialization::track_selectively);推荐答案我认为下面的清洁版本将更加可行。错误代码是指第一次输入Print.hpp第51行。I think the cleaned version below will be more workable. The error code refers to Print.hpp line 51 first input.// MyData.hpp filetypedef struct tagMyData{ std::string id; std::string name; boost::shared_ptr ptMydata;public: MyData(void); MyData(const parameter_strings& parms); virtual ~MyData(void);private: friend class boost::serialization::access; template void serialize(Archive &ar, const unsigned int version) { ar &id; ar &name; ar &ptMydata; ar &version; }} MyData; // MyData.cpp file MyData::MyData(void) { } MyData::~MyData(void) { } MyData::MyData(const parameter_strings & parms) { // implementation aprt } BOOST_CLASS_EXPORT_IMPLEMENT(MyData); BOOST_CLASS_IMPLEMENTATION(MyData,boost::serialization::object_serializable); BOOST_CLASS_TRACKING(MyData,boost::serialization::track_selectively); 这篇关于在Boost序列化中,共享指针不起作用..它给出了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-11 09:37