作者popo4231 (小泰)
看板EE_DSnP
标题[问题] ambiguity of function template overloading
时间Sat Dec 22 22:50:20 2007
code:
#include<iostream>
using namespace std;
template<class T>
T x(T i)
{
return i+1;
}
int x(int i)
{
return i;
}
int main()
{
double d = 1.56;
char c = 'a';
int i = 10;
cout<<x(i)<<"\n"<<x(c)<<"\n"<<x(d)<<endl;
system("pause");
return 0;
}
result:
10
b
2.56
请按任意键继续 . . .
可是竟然没有compile error!
我觉得那两个x函式会产生ambiguity阿
可是好像compiler会先挑非template的执行
why?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.241.177