2014-03-14 2 views
0

"템플릿 함수 포인터"의 유형을 정의 할 수 있습니까? 이러한"템플릿 함수 포인터"의 유형을 정의 할 수 있습니까?

void (*tfp<99>)(); // can't compile 

으로 템플릿 클래스가 할 수있는 것처럼 :

Someclass<99>(); 

더 내 문제를 설명하기 위해, 나는 다음과 같은 코드가 있습니다

template <int N> 
class Foo {}; 

template <int N> 
void foo() {} 

template <int N, template <int> class OP> 
void test_foo(OP<N> op) { std::cout << N << std::endl; } 

내가 test_foo(Foo<99>())를 호출 할 수 있지만, 수 인수가 인 test_foo()으로 전화하기 :

test_foo(Foo<99>());     //OK 
test_foo(foo<99>);      //error: candidate template ignored: could not match '<N>' against 'void (*)()' 
test_foo<void (*)()>(foo<99>);   //error: candidate template ignored: invalid explicitly-specified argument for template parameter 'N' 
test_foo<void (*<99>)()>(foo<99>);  //error: expected expression 
test_foo<void (*<99>)()<99> >(foo<99>); //error: expected expression 

접근 방식 템플릿 매개 변수 N을 에 넣고 foo<99>처럼 test_foo(Foo<99>())처럼 할 수 있습니까? 당신이 할 수

답변

1

C++ (11) 템플릿 별칭 :

당신은 그 fptr 값의 "특성을"할 (또는 &foo<N> 함수 매개 변수에서 템플릿 인수를 추론 할) 수 없습니다
template <int V> using fptr = void (*tfp<V>)(); 

, a의 값 때문에 함수 템플릿 인스턴스화는 이 아니며은 결과 형식에 템플릿 인수를 인코딩합니다.

이것은 클래스 템플릿과 다릅니다.

관련 문제