4

Possible Duplicate:
“invalid use of incomplete type” error with partial template specialization부분 전문화

왜이 작업을 수행 할 수있는 그 것이다 두 번째 경우를 들어

template <typename> struct C {}; 

template <typename T> 
struct A 
{ 
    void foo(int); 
}; 

template <typename T> 
void A<C<T> >::foo(int) 
{ 
} 

을, GCC는 다음과 같은 오류를 제공합니다 :

test.cpp:10:23: error: invalid use of incomplete type 'struct A<C<T> >' 
test.cpp:4:8: error: declaration of 'struct A<C<T> >' 

EDIT :

두 번째 예제가 허용되지 않는 이유를 설명 할 때 멤버 함수를 템플릿으로 만드는 것은 어떤 예제가 효과가 있고 어떤 효과가 없는지 고려하지 않습니다.

template <typename T> 
struct A 
{ 
    template <typename U> 
    void foo(U); 
}; 

template <> 
template <typename U> 
void A<int>::foo(U) 
{ 
} 

을하지만이되지 않습니다 : 그것은이 여전히 작동한다

template <typename> struct C {}; 

template <typename T> 
struct A 
{ 
    template <typename U> 
    void foo(U); 
}; 

template <typename T> 
template <typename U> 
void A<C<T> >::foo(U) 
{ 
} 

그래서 이유 세 번째 예는 전체 전문이 아니기 때문에 함수 템플릿은 (완전히 전문화 할 수있는 수 없습니다 템플릿 매개 변수 U이 여전히 존재 함), 아직 작동합니다.

+0

@Mankarse 다른 문제 인 것 같습니다. –

답변

6

기능 템플릿은 부분적으로 만 특수화 될 수 있습니다.

클래스 템플릿의 멤버 함수가 함수 템플릿이기 때문에이 규칙이 계속 적용됩니다. 당신의 편집에 관해서는


: 다음 일이 명시 적으로 할 수있다 (즉, 완전히) 전문, 14.7.3/1 :

An explicit specialization of any of the following:

— function template

— class template

member function of a class template

— static data member of a class template

— member class of a class template

— member enumeration of a class template

— member class template of a class or class template

member function template of a class or class template

can be declared by a declaration introduced by template<>;

나는 당신의 경우에 적용되는 두 문장을 강조했습니다 . 다른 명시 적 조항이 없으면 해당 기업은 이 아니며은 부분적으로 특수화 할 수 있습니다.

+0

나는이 설명을 살지 모르겠다. 멤버 함수 자체를 템플릿 매개 변수 'U'를 사용하여 템플릿이라고 가정합니다. 그럼에도'A :: foo (U)'는 정의 할 수 있지만'A :: foo (U)'는 정의 할 수 없습니다. 그러나 첫 번째 매개 변수는 템플릿 매개 변수 ('U')를 갖기 때문에 완전한 전문화로 간주 될 수 없습니다. – HighCommander4

+0

@ HighCommander4 : "회원 템플릿"이 아니라 "회원 함수"라고 말했습니다. 질문을 변경하면 대답을 바꿀 수 있습니다 :-) –

+0

완료, 내 편집을 참조하십시오. – HighCommander4

관련 문제