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;
}
어떻게하면됩니까?