I've done operator overloading to "-" for my class graph. It's use isn't totally intuitive (bad coding-I know) but if I do graph3 = graph2-graph1 then graph 3 is supposed to receive only those vertexes in both graph 2 and graph 1.
So, I've written the code and when I run the debugger, the operator- function seems to create a new "graph" to return and it adds the appropriate vertexes to the new graph and then the debugger seems to exit the op- function, but never makes it back to main. It's as if it's waiting for me to enter something. No error messages appear.
Here is the code:
char stringy[100];
//cin>>stringy;
strcpy(stringy,"|12,34,25,2,3,2|(3->2),(2->1),(5->9),(2->1)|");
char* param= new char[sizeof(stringy)];
strcpy(param,stringy);
Graph graph1(param);
char sstring[20] = "|33,34,11|(2->33)|";
Graph graph2(sstring);
cout<<graph2.outSumm()<<endl;
Graph graph3;
//until here everything works fine
graph3= graph1-graph2; //the debugger does this and then
cout<<graph3.outSumm()<<endl;
The operator- function:
Graph Graph::operator- (const Graph& g2) const
{
Graph created;
//goes through "this" list and if value exists in g2 copies it to created
for(int i=0;i<vertList.getSize();i++)
{
if (g2.vertList.find(vertList.read(i))!=999)
created.addVertex(vertList.read(i).getInt());
}
return created;
}
I'm using codeblocks.
Copy constructor:
Graph(const Graph& g2):
maxVal(g2.maxVal),vertList(g2.vertList),edgeList(g2.edgeList){} ;
Assignment operator:
void Graph::operator= (const Graph& g2)
{
if (this==&g2)
{
cout<<"not the greatest idea"<<endl;
return;
}
vertList.delete_List();
edgeList.delete_List();
maxVal=0;
addValues(g2.outSumm());
}