Bru*_*tos 6 c++ templates overloading template-specialization overload-resolution
给出以下代码:
#include <iostream>
using namespace std;
template<typename T> void Print(T t) {
cout << t << endl;
}
template<> void Print<int>(int t) {
cout << "int = " << t << endl;
}
void Print(int i) {
cout << "int2 = " << i << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Print(1.3);
Print("tese");
Print(2);
char c;
cin >> c;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么调用Print(2)不是模糊的,而是调用void Print(int i)?
ps:使用bcc64.exe和cl.exe进行测试.