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