So I saw this question, which basically says that references and iterators are invalidated together.
I get why iterators are invalidated in certain cases, but why are references invalidated?
From a practical standpoint, I don't see why this is required.
Was it just a design decision or is there some practical reason?
EDIT: To clarify, as far as I understand the underlying structure, it's just pointers to the data that will need to be reallocated (the data (and thus the reference to it) can remain intact). Right?
Some test code:
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<string> yourVect;
yourVect.push_back("def");
vector<string>::iterator iter = yourVect.begin();
const string& ref = *iter;
yourVect.insert(yourVect.begin(), "abc");
cout << ref << endl; // !! --- doesn't work - why ?? --- !!
cout << *iter << endl; // obviously doesn't work
}