#include "config.h"
#include <vector>
#include <algorithm>
class Person {
public:
string name;
int age;
Person(string name, int age) {
this->name = name;
this->age = age;
}
};
int main(void) {
vector<Person> v;
v.push_back(Person("Bob", 16));
v.push_back(Person("Gail", 11));
v.push_back(Person("Kim", 18));
v.push_back(Person("Lizy", 12));
v.push_back(Person("Kayle", 15));
vector<Person>::iterator iter = v.begin();
iter = iter + 2;
cout << (*iter).name;
v.erase(iter);
cout << (*iter).name;
v.insert(v.begin() + 1, Person("John", 20));
cout << (*iter).name;
}
벡터랑 덱은 요소가 삽입되거나 삭제되면 반복자가 무효화된다던데 이거 왜 정상작동함??
정상작동은 cout << (*iter).name;이 정상작동 된다구 말한거임!!
항상 무효화되는거 아니다. 일정 capacity에 대해서 일정 threshold를 넘어야 벡터 재할당되면서 이터레이터 터지는거 - return 0;
ㄱㅅ 확인함