forked from chihyang/CPP_Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExer06_51.cpp
More file actions
50 lines (49 loc) · 1.41 KB
/
Copy pathExer06_51.cpp
File metadata and controls
50 lines (49 loc) · 1.41 KB
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
// Warning: This is for verification. It CANNOT be compiled successfully by both compilers.
// The problem lies in line 24.
#include <iostream>
using std::cout;
using std::endl;
void f()
{
cout << "This function takes no parameters." << endl;
}
void f(int)
{
cout << "This function takes an int parameter." << endl;
}
void f(int, int)
{
cout << "This function takes two int parameters." << endl;
}
void f(double, double = 3.14)
{
cout << "This function takes two double parameters." << endl;
}
int main()
{
f(2.56, 42);
f(42);
f(42, 0);
f(2.56, 3.14);
return 0;
}
// ******compile info of cl******
// 用于 x86 的 Microsoft (R) C/C++ 优化编译器 18.00.40629 版版权所有(C) Microsoft C
// orporation。 保留所有权利。
//
// Exer06_51.cpp
// Exer06_51.cpp(24) : error C2666: “f”: 2 个重载有相似的转换
// Exer06_51.cpp(18): 可能是“void f(double,double)”
// Exer06_51.cpp(14): 或 “void f(int,int)”
// 尝试匹配参数列表“(double, int)”时
// ******compile info of g++******
// Exer06_51.cpp: In function 'int main()':
// Exer06_51.cpp:24:12: error: call of overloaded 'f(double, int)' is ambiguous
// f(2.56, 42);
// ^
// Exer06_51.cpp:14:6: note: candidate: void f(int, int)
// void f(int, int)
// ^
// Exer06_51.cpp:18:6: note: candidate: void f(double, double)
// void f(double, double = 3.14)
// ^