提升图递归模板问题

时间:2011-06-21 12:32:09

标签: c++ templates boost-graph

嗨我有一个像:

的提升图
struct Vertex;
struct Edge;



typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Vertex, Edge> Graph_t;


struct Vertex {
};

struct Edge {
    typedef std::vector<Graph_t::vertex_descriptor> intermediate_vertices_t;
    intermediate_vertices_t intermediate_vertices;
};

问题在于Edge类中的递归模板。我需要存储一个顶点向量。

3 个答案:

答案 0 :(得分:2)

您可以使用adjacency_list_traits来解决此问题。此类允许用户访问顶点和边描述符类型,而无需用户提供图的属性类型。

struct Vertex {
};

typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::bidirectionalS>::vertex_descriptor VertexDescriptor;
struct Edge {
    typedef std::vector<VertexDescriptor> intermediate_vertices_t;
    intermediate_vertices_t intermediate_vertices;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Vertex, Edge> Graph_t;

答案 1 :(得分:0)

答案 2 :(得分:0)

我最终使用了一个小包装类,如:

typedef Graph_t::vertex_descriptor vd_t;                           

struct iVertexWrap{                                                
    iVertexWrap(vd_t v) : v(v)
    {}                                                             
    vd_t v;
};

在Edge类之前声明它。