Trích mẫu có vẻ sai, tại sao (c) được gọi thay vì (b)?Trích mẫu có vẻ sai
#include <iostream>
using namespace std;
template<class T> void f(T){cout << "f(T)";}//(a)
template<> void f<>(int*){cout << "f(int*)";}//(b)
template<class T> void f(T*){cout << "f(T*)";}//(c)
//void f(int*){cout <<"POD:f(int*)";}//(d)
int main(int argc,char*argv[])
{
int p = 1;
f(&p);
cout <<endl;
return 0;
}
đầu ra:
f(T*)
Xem [tại sao không chuyên chức năng mẫu] (http://www.gotw.ca/publications/mill17.htm). – juanchopanza
@jogojapan Tôi đã thay đổi tiêu đề của bản sao để phản ánh tốt hơn câu hỏi. – juanchopanza