The vectors will be declared as
vector<Data> A;
vector<const Data *> V;
(Note that V cannot be a vector of const Data &
because references are not Assignable, and vector requires an Assignable template type.)
Assigning a reference from A into V would look like this:
V[i] = &A[i];
I'm not sure what you mean by get_A and get_V. My best guess is that you are referring to what the results of operator[] on A and V are. A[i]
returns a reference to a Data, that is a Data&
. V[i]
technically returns a reference to a const Data pointer, i.e. const Data * &
, but effectively you would use it as a pointer, i.e. a const Data *
.
Regarding the question about A, B, and C: if they are the all vectors of same type, and they do not change size, you could set up V to contain pointers to the elements in each one of them. But if they do change size, then appending an element to, say, A, after having set V up would mean you would have to insert the pointer to the new element of A into the correct offset of V, which is possible but seems like a hassle.
A quick example of setting up such a V would look like this:
vector<Data const *> V;
for (size_t i = 0; i < A.size(); ++i) { V.push_back(&A[i]); }
for (size_t i = 0; i < B.size(); ++i) { V.push_back(&B[i]); }
for (size_t i = 0; i < C.size(); ++i) { V.push_back(&C[i]); }