I'm trying to create a graph, and I'm trying to do this by creating a set of type Vertex and set of type Edge. However, I'm getting this error:
Invalid operands to binary expression ('const Vertex' and 'const Vertex')
Is it even possible to hold objects in sets? I'm not a great coder, this is for my college project. If you see ** surrounding blocks of code, it's because I tried to make those portions bold to try and highlight, but it didn't work. Those ** 's are not in my actual code.
class Vertex
{
public:
Vertex();
Vertex(std::string);
std::string getVertexName();
private:
std::string name;
};
class Edge{
Edge();
Edge(std::string, std::string);
std::string source;
std::string destination;
};
class Graph{
public:
void buildGraph( );
void createVertex(std::string vertexName);
// **
std::set <Vertex> setofvertices;
std::set <Vertex>::iterator itervertex = setofvertices.begin();
std::set <Edge> setofedges;
std::set <Edge>::iterator iteredge = setofedges.begin();
// **
};
Graph* DataSource:: buildGraph()
{
Graph *createdGraph;
//Vertex *createdVertex;
std::ifstream inputFile;
std::string followee, follower;
inputFile.open(this->filename);
if (inputFile.is_open()){
std::stringstream line;
std::string fileLine;
createdGraph = new Graph();
while(true){
getline(inputFile, fileLine);
if (inputFile.eof()) break;
line.clear();
line.str(fileLine);
line >> followee >> follower;
std::cout << followee << " " << follower << std::endl;
// **
createdGraph->setofvertices.insert(followee);
createdGraph->setofvertices.insert(follower);
createdGraph->setofedges.insert(followee,follower);
// **
}
return createdGraph;
}