[英]Visual Studio 2012 error C2039: 'serialize' : is not a member of 'std::shared_ptr<_Ty>'
[英]error C2039: 'serialize' : is not a member of 'std::vector<_Ty>'
//define
typedef std::vector<double> vertex_data;
//serialise
std::ostringstream oss;
boost::archive::text_oarchive oa(oss);
vertex_data data = .......get_data();//returns vertex_data
oa & m_state & data;//send this data over network
//deserialise
std::istringstream iss(recvd_msg);
boost::archive::text_iarchive ia(iss);
vertex_data data;
ia>>data; //error here
為什么在反序列化期間出現此錯誤?
問題是你沒有定義std :: vector的特殊序列化,所以它回退到默認的序列化,它試圖在要序列化的類上調用一個名為serialize的成員。
要獲取std :: vector的特殊代碼,您需要包含<boost/serialization/vector.hpp>
,如下所述:
http://www.boost.org/doc/libs/1_54_0/libs/serialization/doc/serialization.html#models
要使用boost序列化器進行反序列化,您需要使用運算符&,就像您要進行序列化一樣。
std::istringstream iss(recvd_msg);
boost::archive::text_iarchive ia(iss);
vertex_data data;
ia & data;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.