추론 된 템플릿이 잘못된 것으로 보입니다. 왜 (b)가 아닌 (c)가 호출 되었습니까?템플릿 공제가 잘못되었습니다.
#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;
}
출력 :
f(T*)
참조 [기능 템플릿을 전문으로하지 왜 (http://www.gotw.ca/publications/mill17.htm). – juanchopanza
@ jogojapan 질문을 더 잘 반영하기 위해 복제본의 제목을 변경했습니다. – juanchopanza