1
在下面的例子中,我嘗試插入一個元素到std::map
並獲取到最後一個插入元素的迭代器,但我無法修改它。修改最後一個插入到std :: map
#include <map>
struct X {
int x;
};
struct Y {
int y;
};
int main()
{
X x = {1};
Y y = {2};
std::map <X, Y> Z;
std::pair<std::map<X, Y>::iterator,bool> lastval = Z.insert(std::pair<X, Y>(x, y));
// Error: Expression must be a modifiable lvalue;
lastval.first->first.x = 0;
}
我該怎麼做?