I have a problem using the data base "map".
I am writting a progrem that implement BFS (breadth first search) at graphs.
In oreder to keep the "key" (string) and the "value" (Vertex- a class I created)
I use :
map<string, Vertex*> graph
"graph" is a field at class "Graph" that include some functions. One of the functions is " void addv(string& key)" - her goal is to add a new Vertex to the map. here a copy of the function:
void Graph::addv(string& key) // add vertex to the graph
{
// initilazited the map by values
string tempKey = key;
Vertex v(tempKey);
v.initialize(tempKey); // at the begining, the color of all vertexes is
//"white".
Vertex * p =&v;
graph.insert(pair<string,Vertex*>(tempKey, &v));
}
From the the main program I run this program:
int main()
{
Graph g;
string v1, v2, e1,e2 ,name;
cout << "enter vertexes" << endl;
cin >> v1;
cin >> v2;
g.addv(v1); g.addv(v2);
}
My problem is the "return values" of the function. At the running the program my input value were: v1= 'A', v2= 'B'. When I debug the program I noticed that when the process get to mention fuction, the value of the "graph" nearly to exit from the function were as you can see at the picture below:
But at final step of the process at the fuction, the values change as you can see at this picture:
As you can see the "key" value at parmeter "second" change to " " instead of "A".
Thank you for your help.