I am trying to make a generic graph structure, but I am running into this circular dependency between vertices and edges. I define my Vertex and Edge classes like so:
template<typename EdgeType>
struct Vertex {
std::vector<EdgeType> successors;
};
template<typename EdgeCostType, typename VertexWrapper>
struct Edge {
EdgeCostType cost;
VertexWrapper source;
VertexWrapper dest;
};
I would like to instantiate it with something like Vertex<Edge<int, std::shared_ptr<decltype(v)>>> v;
, but I obviously cannot. What can I do to resolve this circular dependency?
Edit:
I think what this problem boils down to is using the current template as a template parameter to one of the template parameters of the current template, e.g. how to do something like this:
template<typename VertexWrapper>
struct Vertex {
std::vector<pair<int, VertexWrapper<Vertex>>> successors;
};
Aucun commentaire:
Enregistrer un commentaire