この質問をするために、コードの一部を単純化する必要がありました。ただし、以下のコードでは、参照型として宣言していないという事実はx
、関数が終了するとデクリメントの変更が「忘れられる」ことを意味しますか?
これを修正する最も賢明な方法は、 ?x
として宣言することです。AnotherClass& x
void MyClass::myFunc(unordered_map<int, AnotherClass>* dictionary, int z, int y){
AnotherClass x = dictionary->at(z);
//Does this change on x get "forgotten" in terms of what dictionary stores
//once myFunc() has finished, because x is not a reference/pointer type?
x.changeSomething(y--);
}
class MyClass{
public:
private:
myFunc(unordered_map<int, AnotherClass>* dictionary, int z);
unordered_map<int, AnotherClass>* dictionary
};