作者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