2
我想序列化一个boost :: array,包含已经可序列化的东西。序列化升压阵列
如果出现此错误:
error C2039: 'serialize' : is not a member of 'boost::array<T,N>'
我曾尝试包括串行/ array.hpp头,但它并没有帮助。 是否有另一个标题包含?
感谢
编辑: 删除了错误的链接
我想序列化一个boost :: array,包含已经可序列化的东西。序列化升压阵列
如果出现此错误:
error C2039: 'serialize' : is not a member of 'boost::array<T,N>'
我曾尝试包括串行/ array.hpp头,但它并没有帮助。 是否有另一个标题包含?
感谢
编辑: 删除了错误的链接
你需要显示包含了boost ::数组中的类的代码。由于boost :: array是STL-compliant,应该没有理由这是行不通的。您应该在this示例中执行类似bus_route和bus_stop类的操作。
::数组必须申报的boost ::系列化::访问作为朋友类并实现如下序列化方法包含在刺激方案中的类:
class bus_stop
{
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const bus_stop &gp);
virtual std::string description() const = 0;
gps_position latitude;
gps_position longitude;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & latitude;
ar & longitude;
}
protected:
bus_stop(const gps_position & _lat, const gps_position & _long) :
latitude(_lat), longitude(_long)
{}
public:
bus_stop(){}
virtual ~bus_stop(){}
};
一旦做到这一点,一个std容器应能够序列化bus_stop:
class bus_route
{
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const bus_route &br);
typedef bus_stop * bus_stop_pointer;
std::list<bus_stop_pointer> stops;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
// in this program, these classes are never serialized directly but rather
// through a pointer to the base class bus_stop. So we need a way to be
// sure that the archive contains information about these derived classes.
//ar.template register_type<bus_stop_corner>();
ar.register_type(static_cast<bus_stop_corner *>(NULL));
//ar.template register_type<bus_stop_destination>();
ar.register_type(static_cast<bus_stop_destination *>(NULL));
// serialization of stl collections is already defined
// in the header
ar & stops;
}
public:
bus_route(){}
void append(bus_stop *_bs)
{
stops.insert(stops.end(), _bs);
}
};
注意的重要线路:
ar & stops;
它将自动迭代std容器,在这种情况下是bus_stop指针的std :: list。
错误:
error C2039: 'serialize' : is not a member of 'boost::array<T,N>'
表示存在的类的boost ::数组中要么没有宣布的boost ::系列化::访问作为朋友类或尚未实施的模板方法连载。
是否有没有去使用boost :: serialization的具体原因。显然你已经有了提升,为什么不在那里使用它呢? – pmr 2010-06-15 15:07:54
@pmr我的解释是在这里使用了boost :: serialization。 – manifest 2010-06-15 22:02:05
@manifest链接指向一些不同的序列化库。绝对不会提升。 – pmr 2010-06-16 11:11:28