Calling a function that takes an array as argument

This is an adaption of a Chapter 7 review question from Stephen Prata's C++ Primer Plus. I want to output the maximum value in the array as calculated in the function x but am getting an error on the line:
cout << x (boy[],3);
Any ideas?


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
27
28
29
 #include <iostream>
using namespace std;
int  x(const int  b[], int size);

int main()
{
	int dog[3] = { 12, 15, 22 };
	cout << x (dog[],3);
	return 0;
}

int  x(const int b[], int size)
{
	    int max;
		if (size < 1)
		{
			cout << "Invalid array size of " << size << endl;
			cout << "Returning a value of 0\n";
			return 0;
		}
		else 
		{
			max = b[0];
			for (int i = 1; i < size; i++)
				if (b[i] > max)
					max = b[i];
			return max;
		}
}
Line 8 should be: cout << x(&dog[0], 3); // or x(dog,3);
What was the exact compiler error message? The purpose of the message is to tell what the compiler does not understand. Learning to understand those messages is both important and useful. Alas, some messages are cryptic.


http://www.cplusplus.com/doc/tutorial/arrays/ has more about "Arrays as parameters".
Thank you both very much. The error message was:
syntax error: ']'
Topic archived. No new replies allowed.