Hi, I've got a problem using the Vector-class. When using it to implement a version of Dijkstra's algorithm I ran into reference-issues, so I tried this out:
cout << myVector[0].getColor();
myVector[0].setColor(myVector[0].getColor()+1);
cout << " " << myVector[0].getColor();
getColor and setColor are simple getter and setter for an integer-value. The above listed code results in the following output: "1 1", which isn't exactly what I'd like to happen. Can someone help me please? What do I have to change in order to get "1 2" put out?
The first line prints the excepted result ("Vertex 001 with label A
Vertex 001 with label A).
It also does it repeatedly. The second line doesn't do what it's intended to do at all. It prints out "Vertex " and then doesn't print out anything anymore, even if I put the working line after it. I'm quite confused as I don't understand why the first line works and the second one doesn't. If it helps: g is a Graph and c is a Component, which holds certain vertices of g in its member vertices. These are the vectors I meant when I wrote "myVector" above.
I try to avoid the subscript operator whenever iterators are available. I realize Dijkstra's algorithm indexes into arrays, and I seem to recall they were arrays of distance values...
Anyway, I hope this helps.