I have to create a vector containing selected elements of another vector. Changes made in one vector should reflect in the other vector too. So I have to use reference of the elements which I intend to copy.
For example,
std::vector<int> a{1,2,3,4,5,6};
std::vector<int> b;
Suppose if I copy odd numbers with reference to b
vector, b
will contain 1,3 and 5. If I change the values of b
, same changes should be seen in a
vector also.
What it the method in STL to do this?
EDIT:
I was in assumption that same memory address location can be shared by more than one variables.
The purpose of the above code was, to pass smaller vector of unknown variables, to an external solver to be solved. Since changes will be automatically updated in the larger vector, I don't need to keep track of it. It seems I have to use pointers for the above purpose.