'Ambiguos' error with global variables

What does it mean if you get an error calling something ambiguous? It is happening at my int mult[max] = part. I am trying to have any arguments that are passed to or from my function multiply_me
to only be global. I am having trouble passing arrays as global?


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

 #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>

using namespace std;

const int x = 11;
const int y = 11;
const int max = 11;
void multiply_me(int result_nums[x][y], int nums[]); 
int j = 0;
int i = 0;
int mult[max] = {0,1,2,3,4,5,6,7,8,9,10};
int result_mult[x][y]; 
int main()
{
	
	
	string ans = "yes";

	while(ans == "yes")
	{

	cout<<"This program will output the multiplication tables for the integers 0-10"<<endl;

	
	
	cout<<endl;
	
	multiply_me(result_mult, mult); 

	for(i = 0; i<11; i++)
		
		{for(j = 0; j<11; j++)
			{cout<<setw(4)<<result_mult[i][j]; 
}
	cout<<endl;
	}

	cout<<endl;
	cout<<"Would you like to run this again?"<<endl;
	cin>>ans;
	}
	system("pause");

	return 0;
}

void multiply_me(int result_nums[x][y], int nums[])
{
	for(i = 0; i<11; i++) 
		for(j = 0; j<11; j++) 
			 result_nums[i][j] = nums[i]*nums[j]; 
	

	return;
}
What does it mean if you get an error calling something ambiguous?

this typically means that the compiler is confused. Your compiler probably already defined a variable with the name max and doesn't know which max you are referring to. The solution would be to use a different name.

I am trying to have any arguments that are passed to or from my function multiply_me to only be global.

This is bad programming global variables should be a last resort.
Ambiguous means there are multiple possible meanings so the compiler doesn't know what to pick.

max is ambiguous in your program because you have a variable named max defined on line 11. There is also a function std::max in the standard library. To make it not ambiguous you will have to specify that you mean max in the global namespace by putting :: in front of the variable name.
 
int mult[::max] = {0,1,2,3,4,5,6,7,8,9,10};

This is a good example why using using namespace std; is not such a good idea. If you didn't have using namespace std; it wouldn't be ambiguous because you would have to write std::max if you mean max in the standard library.
I know using global variables isn't very robust, but its for an assignment, so i have to. Ok, where am i defining it twice at? Is the only option to change it to another name? not a huge deal, but I'd have to go back and change some other things i think and i'd rather not if there is an easier fix. I'll take a look again
Ok, thank you! that makes a lot of sense now.
Topic archived. No new replies allowed.