我只是P值插入到下个地图,我得到它的地图,它的值应该是20,但不是,为什么?C++ 11 share_ptr作为值映射关键
typedef shared_ptr<BaseObject> PtrValue;
class CodeExecuteContext{
public:
map<string,PtrValue> varIdentPool;
};
class BaseInteger :public BaseObject{
public:
int value;
BaseInteger(int val):value(val){
enumObjType = INT;
};
};
...
PtrValue pValue = rightNode->executeCode(context);
context.varIdentPool.insert(make_pair(leftNode.idName,pValue));
BaseInteger * baseInteger = (BaseInteger *) pValue.get();
cout << "==AssignmentASTFork== insert [ " << leftNode.idName << " , " << baseInteger->value << " ]" <<endl;
map<string,PtrValue>::iterator it;
for (it = context.varIdentPool.begin() ; it!=context.varIdentPool.end();it++) {
BaseInteger * baseInteger = (BaseInteger *) it->second.get();
cout << "[key : " << it->first << ", value : " << baseInteger->value << endl;
}
结果:
== AssignmentASTFork ==插入[精氨酸,20]
[键:精氨酸,值:32742]
我的猜测是,该地图已包含此键更改地图中的价值。 '地图:: insert'是无操作在这种情况下 - 它不更换新价值现有的值。 –