Suppose I have a std::vector<T> v
, and a T t
, is it possible for me to add t
to v
while maintaining reference to the vector element its assigned to? I know it's probably unsafe to do this, but I just want to know to be honest. An example of what I'm achieving is below:
std::vector<int> v;
int t = 1;
v.push_back(t);//replace with magic method
// now v[0] = t;
t = 2;
std::cout << v[0] << std::endl; // OUT: 2, instead of 1 because t, i.e. v[0] changed.