C++ 图属性映射的boost序列化

C++ 图属性映射的boost序列化,c++,dictionary,serialization,boost,graph,C++,Dictionary,Serialization,Boost,Graph,我试图用以下定义序列化boost::graph: typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property, boost::property<boost::edge_weight_t, float> > mygraph_t; typedef boost::prop

我试图用以下定义序列化boost::graph:

 typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property,
                                  boost::property<boost::edge_weight_t, float> > mygraph_t;
    typedef boost::property_map<mygraph_t, boost::edge_weight_t>::type WeightMap;
    typedef mygraph_t::vertex_descriptor vertex;
    typedef mygraph_t::edge_descriptor edge_descriptor;


mygraph_t topoGraph;
WeightMap weightMap;
typedef boost::邻接列表mygraph\t;
typedef boost::property_map::type WeightMap;
typedef mygraph_t::顶点描述符顶点;
typedef mygraph_t::edge_描述符edge_描述符;
mygraph\u t地形图;
权重图权重图;
该问题是由于我试图序列化“weightMap”引起的

尽管我包含了我认为合适的头文件,但它仍然失败,并显示以下错误消息: “boost/graph/adj_list_serialize.hpp”

/usr/include/boost/serialization/access.hpp:118:9:错误:“struct boost::adj_list_edge_property_map”没有名为“serialize”的成员
t、 序列化(ar、文件版本);
^

非常感谢您的帮助。

为了序列化任何类的对象,该类必须提供serialize()模板函数。显然,类型adj_list_edge_属性_map没有该功能。解决此问题的一种方法是创建一个包装类W来存储该类型的对象,并添加W::serialize(),该类通过序列化weightMap的组件来实现。然后,不是序列化weightMap,而是序列化W。

为了序列化任何类的对象,该类必须提供serialize()模板函数。显然,类型adj_list_edge_属性_map没有该功能。解决此问题的一种方法是创建一个包装类W来存储该类型的对象,并添加W::serialize(),该类通过序列化weightMap的组件来实现。然后不是序列化weightMap,而是序列化W。

我无法复制它

这是一个在线版本

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adj_list_serialize.hpp>

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property,
                                          boost::property<boost::edge_weight_t, float> > mygraph_t;
typedef boost::property_map<mygraph_t, boost::edge_weight_t>::type WeightMap;
typedef mygraph_t::vertex_descriptor vertex;
typedef mygraph_t::edge_descriptor edge_descriptor;

#include <boost/archive/text_oarchive.hpp>
#include <iostream>

int main() {
    mygraph_t topoGraph;
    WeightMap weightMap;

    boost::archive::text_oarchive oa(std::cout);
    oa << topoGraph;
}
#包括
#包括
typedef boost::邻接列表mygraph;
typedef boost::property_map::type WeightMap;
typedef mygraph_t::顶点描述符顶点;
typedef mygraph_t::edge_描述符edge_描述符;
#包括
#包括
int main(){
mygraph\u t地形图;
权重图权重图;
boost::archive::text\u oarchive oa(std::cout);
oa我不能复制它

这是一个在线版本

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adj_list_serialize.hpp>

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property,
                                          boost::property<boost::edge_weight_t, float> > mygraph_t;
typedef boost::property_map<mygraph_t, boost::edge_weight_t>::type WeightMap;
typedef mygraph_t::vertex_descriptor vertex;
typedef mygraph_t::edge_descriptor edge_descriptor;

#include <boost/archive/text_oarchive.hpp>
#include <iostream>

int main() {
    mygraph_t topoGraph;
    WeightMap weightMap;

    boost::archive::text_oarchive oa(std::cout);
    oa << topoGraph;
}
#包括
#包括
typedef boost::邻接列表mygraph;
typedef boost::property_map::type WeightMap;
typedef mygraph_t::顶点描述符顶点;
typedef mygraph_t::edge_描述符edge_描述符;
#包括
#包括
int main(){
mygraph\u t地形图;
权重图权重图;
boost::archive::text\u oarchive oa(std::cout);

oa我认为您没有包括以下文件:

#include <boost/graph/adj_list_serialize.hpp>
#包括

此头文件包含以非侵入模式加载/保存邻接列表对象所需的序列化方法。

我认为您没有包含以下文件:

#include <boost/graph/adj_list_serialize.hpp>
#包括

此头文件包含以非侵入模式加载/保存邻接列表对象所需的序列化方法。

我认为您没有使用Boost序列化。您不需要更改类型以使其可序列化我认为您没有使用Boost序列化。您不需要更改类型以使其可序列化以提供如果您的问题有价值,请发布相关代码段,以说明您如何继续序列化。如果您的问题有价值,请发布相关代码段,以说明您如何继续序列化。