In C++, how to make a copy of an existing vector pointing to the same allocated memory ?
e.g :
vector<int> o1;
o1.push_back(1);
vector<int> o2;
//Make o2 share same memory as o1
o2[0]=2;
cout << o1[0]; //display 2
EDIT : I haven't been clear about the objective : if o1 is allocated on the heap and gets destroyed, how can I create an object o2 that would point to the same allocated memory as o1 to keep it outside of the o1 scope ?