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

时间:2014-03-22 00:39:42

标签: c++ visual-studio-2012 serialization boost

我正在尝试使用boost序列化共享指针,但它会出错: 错误1错误C4308:负整数常量转换为无符号类型c:\ users \ allwork \ hope \ lib \ boost_1_55_0 \ boost \ mpl \ print.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);

1 个答案:

答案 0 :(得分:0)

不要忘记包含

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