I just insert pValue to map next i get it from map ,and its value should be 20 ,but not, why?
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;
}
result:
==AssignmentASTFork== insert [ arg , 20 ]
[key : arg, value : 32742]
Aucun commentaire:
Enregistrer un commentaire