看板 EE_DSnP 關於我們 聯絡資訊
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