call of overloaded '...' is ambiguous

Hello to all, I am new hereabouts and in c ++.

I do not speak and write English, am going to be clear possible using a translator

I am doing a practice and do not understand the following thing:
To do the exercise with parameters for fault but these go out for me messages error.

Original code
http://codepad.org/WdtNIOgV

Code modified with messages error
http://codepad.org/o1M4DQlz

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
60
61
62
63
#include <iostream>
using namespace std;

int mayor(int x, int y=2);
int mayor(int x, int y=2, int w=3);
int mayor(int x, int y=2, int w=3, int s=4);
 
int main()
{
 cout << mayor(13, 4) << endl;
 cout << mayor(15, 45, 23) << endl; 
 cout << mayor(10, 12, 56, 21) << endl;

 return 0; 
}

int mayor(int x, int y)
{ 
 if(x>y) return x;
 else return y;
}
 
int mayor(int x, int y, int w)
{ 
 return mayor(mayor(x, y), w);
}

int mayor(int x, int y, int w, int s)
{ 
 return mayor(mayor(x, y), mayor(w, s)); 
}
/*
Errores de compilacion
In function `int main()':
 
10: error: call of overloaded `mayor(int, int)' is ambiguous
4: note: candidates are: int mayor(int, int)
5: note:                 int mayor(int, int, int)
6: note:                 int mayor(int, int, int, int)

11: error: call of overloaded `mayor(int, int, int)' is ambiguous
5: note: candidates are: int mayor(int, int, int)
6: note:                 int mayor(int, int, int, int)

 In function `int mayor(int, int, int)':
 
25: error: call of overloaded `mayor(int&, int&)' is ambiguous
18: note: candidates are: int mayor(int, int)
24: note:                 int mayor(int, int, int)
6: note:                 int mayor(int, int, int, int)

In function `int mayor(int, int, int, int)':
 
30: error: call of overloaded `mayor(int&, int&)' is ambiguous
18: note: candidates are: int mayor(int, int)
24: note:                 int mayor(int, int, int)
29: note:                 int mayor(int, int, int, int)

30: error: call of overloaded `mayor(int&, int&)' is ambiguous
18: note: candidates are: int mayor(int, int)
24: note:                 int mayor(int, int, int)
29: note:                 int mayor(int, int, int, int)
*/


Maybe my question is very basic but I am learning
Regards from Argentina
1
2
3
4
5
6
7
8
9
10
11
12
13
int mayor(int x, int y=2);  // func a
int mayor(int x, int y=2, int w=3); // func b
int mayor(int x, int y=2, int w=3, int s=4);  // func c

//...

cout << mayor(13, 4) << endl;  // which function does this call?

/*
it could call func a:   mayor(13,4)
it could call func b:   mayor(13,4,(3))  // (3) is default param
it could call func c:   mayor(13,4,(3),(4))  // more default params
*/


The compiler doesn't know which function you want to call. That's why it's giving you the error.

To solve, get rid of those default parameters. They don't do anything for you anyway.
Topic archived. No new replies allowed.