I'm trying to build a class of a graph, which is represented by edges and vertices.
I have implemented the edges as a string set, and the vertices as a string set, and would like to create methods in order to create intersections and unions between my created graphs. This is the class:
class Graph {
public:
string name;
std::set<string> vertices;
std::set<string> edges; //<v1,v2> format
Graph()= default;
Graph(const Graph&) = default;
~Graph() = default;
Graph graphUnion(const Graph& graph);
Graph graphIntersection(const Graph& graph);
};
I used the std::set_intersection function for my method:
Graph Graph::graphIntersection(const Graph& graph){
Graph new_graph;
std::set<string> new_vertices;
new_vertices.end() = std::set_intersection(this->vertices.begin(), this->vertices.end(), graph.vertices.begin(),
graph.vertices.end(), new_vertices.begin());
std::set<string> new_edges;
new_edges.end() = std::set_intersection(this->edges.begin(), this->edges.end(), graph.edges.begin(),
graph.edges.end(), new_edges.begin());
new_graph.vertices = new_vertices;
new_graph.edges = new_edges;
return new_graph;
}
Yet when I try to run it I get the following error, which has something to do with the set_intersection function in
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:5415:27: error: no viable overloaded '='
*__result = *__first1;
~~~~~~~~~ ^ ~~~~~~~~~
Please help me identify this error since I can't tell what is the problem here...
Thank you!
Aucun commentaire:
Enregistrer un commentaire