#include <iostream>
using namespace std;
float func (float x);
float func (double y);
int main(void)
{
cout << func (10.1) << " "; //没有歧义性
cout << func (10); //产生歧义性
return 0;
}
float func (float x)
{
return x;
}
float func (double y)
{
return -y;
}
$ g++ quote3.cc -o quote3
quote3.cc: In function ‘int main()’:
quote3.cc:11: error: call of overloaded ‘func(int)’ is ambiguous
quote3.cc:4: note: candidates are: float func(float)
quote3.cc:5: note: float func(double)
#include <iostream>
using namespace std;
int func(int i);
int func(int i, int j = 1);
int main(void)
{
cout << func(8, 9) << " "; //没有歧义
cout << func(8); //产生歧义
return 0;
}
int func (int i)
{
return i;
}
int func (int i, int j)
{
return i * j;
}
g++ quote2.cc -o quote2
quote2.cc: In function ‘int main()’:
quote2.cc:10: error: call of overloaded ‘func(int)’ is ambiguous
quote2.cc:4: note: candidates are: int func(int)
quote2.cc:5: note: int func(int, int)
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |