So I am trying to make a function that adds a value to an array from another array and it`s giving me this error.
1 2 3 4 5
void combine_Array(int* arr[10], int* arr1[5], int x = 5, int y = 5) {
for (arr, arr1, x, y; x != 10; x++, y--) {
arr.insert(arr.end()-1, arr1.begin()+1);
}
}
#include <iostream>
constexprint MAXSIZEARR{ 10 }; // <--- Only have to make a change here to change everything.
constexprint MAXSIZEARR1{ 5 }; // <--- Only have to make a change here to change everything.
void combine_Array(int arr[MAXSIZEARR], int arr1[MAXSIZEARR1], int x = 5, int y = 5)
{
for (int lc = 0; lc < MAXSIZEARR1; lc++) // <--- Assumes that arr is empty.
arr[lc] = arr1[lc];
}
int main()
{
int arr[MAXSIZEARR]{};
int arr1[MAXSIZEARR1]{ 1, 2, 3, 4, 5};
int x{ 5 }, y{ 5 };
combine_Array(arr, arr1, x, y);
for (int lc = 0; lc < MAXSIZEARR; lc++)
{
std::cout << ' ' << arr[lc] << ((lc < 9)?", " : "\n");
}
return 0;
}
As I said in the comments this works for "arr" being emty to start with. If "arr" would already have elements filled in than the subscript for arr would have to start with a different number.
In the function "combine_Array" giving "x" and "y" a default value may be nice, but could be a problem with out you realizing it. Also "x" and "y" are never used in the function for right now, but could be useful in the future.