所以我有这个:
//sons is an attribute of the object node that is a vector<Node*> that is initialized before
map<string,Node*> nodes;
string node_id = "node";
string son_id = "son";
Node *node = new Node(node_id, matrix, son_id, Prim);
cout << "Before " << node << endl;
cout << "Value of sons before map: " << node->sons[0] << endl;
nodes[node_id] = node;
cout << "After: " << nodes.find(node_id)->second << endl;
cout << "Value of sons after map: " << nodes.find(node_id)->second->sons[0];
我得到这个输出(从执行到执行的内存位置不同):
Before: 0x9dfdda8
Value of sons before map: 0xbff1a774 // consistant with memory position with created obj
After: 0x9dfdda8
Value of sons after map: 0
为什么会发生这种情况,我该如何解决?!我一直在寻找解决方案并试图解决这个问题 4 个小时...