gpt4 book ai didi

c++ - 错误 C2039 : 'serialize' : is not a member of 'std::vector<_Ty>'

转载 作者:太空狗 更新时间:2023-10-29 19:46:05 26 4
gpt4 key购买 nike

//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

关于c++ - 错误 C2039 : 'serialize' : is not a member of 'std::vector<_Ty>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17882870/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com