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;
};
template <typename> class VertexWrapper
? Also, why do you have both C++11 and C++17 tags? Which standard are you targeting? – Goldbergtemplate <typename> typename VertexWrapper
– BattementVertexWrapper
type argument always supposed to be of the formstd::shared_ptr<decltype(v)>
orsome_template_here<decltype(v)>
? – Nakamura