저는 map<int, Button*>
입니다. 여기에서 버튼 클래스는 여러 속성, 특히 position이라는 정수 변수를 가지고 있습니다.지도의 두 요소 교환하기
Button 클래스에서 두 위치를 바꾸려면 항상 키 = 단추 - 위치로 키를 변경해야하며 맵이어야합니다.
이예 (indexFirst 및 indexSecond이 알려져있다) :
나는 (인덱스를 나타내는) (지우기 사용)하고 다시 삽입지도의 두 위치를 삭제하는 생각
map<int, Button*> buttons;
int posOfFirst = buttons.find(indexFirst)->second->getPos();
int posOfSecond = buttons.find(indexSecond)->second->getPos();
Button* button1 = buttons.find(indexFirst)->second;
Button* button2 = buttons.find(indexSecond)->second;
buttons.erase(indexFirst);
buttons.erase(indexFirst);
buttons[posOfSecond] = button2;
buttons[posOfFirst] = button1;
그러나이되지 나타납니다 개체를 변경합니다. 왜?
하지만 어디에서 스왑을합니까? 코드를 살펴보면 나는 그것을 보지 못했습니다. Button1은 indexFirst 또는 posOfFirst 위치에 있으며 button2는 indexSecond 또는 posOfSecond 위치에 있으며 코드에서 변경되지 않았습니다. – Amadeus