Home > Back-end >  Array, which elements links to elements of another array
Array, which elements links to elements of another array

Time:07-07

I want to have an array each elements of each somehow indicates some element of another resizable array I tried:

vector <int> a={1,2,3};
vector <int*> b={*(a[0]),*(a[1]),*(a[2]));

But every editing of size of vector a, copies himself to empty place of memory, so pointers in array b links to an empty place

CodePudding user response:

Is this solution solve your problem? You can access to a address indices through b. Be sure of the integrity of a when you interact with b.

std::vector<int> a{ 1, 2, 3};
std::vector<int>& b{ a };

CodePudding user response:

std::list is close to answer, but, how I understood, deleting elements will move pointers after this element. So it will be faster to store indexes instead of points and make functions swap, erase and add by myself. Array, which elements links to elements of another array This question was the closest

  • Related