My goal is to take 3 standard integer arrays and use vector methods to manipulate them without having to copy all the array elements into a separate vector array.
The reason I want to do this without copying array elements is because these will be very large arrays and efficiency is a priority.
Here are two examples of what I'd like it to look like:
- Simplest example:
int arr[10000];
int *ptr;
std::vector<int> & v = ptr;
v.push_back(10);
- Function example:
// Function that inputs 3 integer arrays and creates pointers to them.
void use_vector(int *dst, int *src1, int *src2) {
//creates vector references (without copying the original array elements)
std::vector<int> & v_dst = dst;
std::vector<int> & v_src1 = src1;
std::vector<int> & v_src2 = src2;
// do something using vector methods:
v_dst.push_back( v_scr1.size() + v_scr2.size() );
}
In both cases, I get this error message:
error: invalid initialization of reference of type ‘std::vector<int>&’ from expression of type ‘int*’
std::vector<int> &v = ptr;
Ideally the vectors are references (std::vector &), but they could also be pointers (std::vector *) if references aren't possible.
std::vectorrequires its own copy of the elements.push_backfor c-arrays