在Boost序列化中,boost_shared指针不会编译.给错误

In Boost serialization,boost_shared pointer does not compile.. give error

本文关键字:指针 编译 错误 shared 序列化 Boost boost      更新时间:2023-10-16

我正在尝试使用boost序列化共享指针,但它给出了错误:c:usersallworkhopelibboost_1_55_0boostmplprint.hpp 51 1输入

我甚至尝试了在链接- https://stackoverflow.com/questions/22409755/boost-serialization-fails-gives-compile-time-error-c4308给出的解决方案但问题仍然存在。

如果我注释行- " ar &MyStruct;"错误发生。请告诉我当前代码中存在的错误或问题。

代码如下:

//MyStruct.hpp文件

struct MyStruct
{
std::string rollno;
std::string address;
***boost::shared_ptr<MyStruct> Mydata;*** 
private:
friend class boost::serialization::access;
template
void serialize(Archive &ar, const unsigned int version)
{
ar & rollno;
ar & address;
ar & Mydata; 
} 
public:
MyStruct(void);
MyStruct(const parameter_strings & parms);
virtual ~MyStruct(void);
};
}
// MyStruct.cpp file
MyStruct::MyStruct(void)
{
}
MyStruct::~MyStruct(void)
{
}
MyStruct::MyStruct(const parameter_strings & parms)
{
// implementation 
}
BOOST_CLASS_EXPORT_IMPLEMENT(MyStruct);   BOOST_CLASS_IMPLEMENTATION(MyStruct,boost::serialization::object_serializable);
BOOST_CLASS_TRACKING(MyStruct,boost::serialization::track_selectively);

别忘了包括

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