"Expression must have a class type"

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);
	}
}
Hello nerol0,

Welcome to the forum.

Your for loop is all wrong. In the first section the use of the comma operator may not work the way that you want.

In the middle part if x = 200 it would be true, but not what you are looking for. I believe what you want is "x < 10".

The last part should work.

It will take me a few minutes to figure out what you will need to do. I will have something in about an hour or so after breakfast.

In the mean time have a look at this:
http://www.cplusplus.com/doc/tutorial/control/#for

Hope that helps,

Andy
arr.insert(arr.end()-1, arr1.begin()+1);
How did you get this idea that an array has an insert , end, begin method, which it doesn't.
It would be easier if you use a vector.
http://www.learncpp.com/cpp-tutorial/6-16-an-introduction-to-stdvector/
Hello nerol0,

My guess at what you may have done and how to fix what you have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

constexpr int MAXSIZEARR{ 10 };  // <--- Only have to make a change here to change everything.
constexpr int 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.

Hope that helps,

Andy
Topic archived. No new replies allowed.