Okay so I have an std::list of structs called DigraphEdge.
Here's 3 crucial code segments:
//DigraphVertex Struct
template <typename VertexInfo, typename EdgeInfo>
struct DigraphVertex
{
VertexInfo vinfo;
std::list<DigraphEdge<EdgeInfo>> edges;
DigraphVertex(VertexInfo v, std::list<DigraphEdge<EdgeInfo>> l) : vinfo(v), edges(l) {}
}
//DigraphEdge struct
template <typname VertexInfo, typename EdgeInfo>
struct DigraphEdge
{
int fromVertex, toVertex;
EdgeInfo einfo;
DigraphEdge(int from, int to, EdgeInfo e) : fromVertex(from), toVertex(to), einfo(e) {}
}
//map that contains vertices and information about the vertices
std::map<int, DigraphVertex<VertexInfo,EdgeInfo>> digraphMap;
Basically the map contains a key(int) and a vertex(DigraphVertex). Each vertex contains information about that vertex(vinfo) and a list of its outgoing edges of type DigraphEdge. And each edge contains information about which vertices the edge begins(fromVertex) and ends(toVertex), as well as information about that edge (einfo).
The key is custom and will always be the same as fromVertex. Example, if I have an edge from 0 to 9, and 0 to 3 --- both of these edges will be stored in the edges list in key 0.
There is this function called addEdge that I'm having problems with. addEdge takes in 3 things; int fromVertex, int toVertex, and EdgeInfo einfo. Basically what I need to do is add a new edge into the edges list located at the key/fromVertex.
I've been doing this but the compiler's not recognizing the insert function that's present in std::list. I'm honestly not sure how to go about adding to that list. I feel like it's a roundabout way to create a new list inside addEdge, copy all the existing edges into that list, add the new edge, and then set the new set of edges equal to the old list.
template <typename VertexInfo, typename EdgeInfo>
void Digraph<VertexInfo, EdgeInfo>::addEdge(int fromVertex, int toVertex, const EdgeInfo& einfo)
{
//check if the edge already exists//
digraphMap.find(fromVertex)->second.edges.insert(new DigraphEdge<EdgeInfo>(fromVertex,toVertex,einfo));
}
Aucun commentaire:
Enregistrer un commentaire