2013-07-06 6 views
2

:템플릿 클래스에서 템플릿 멤버 함수를 특수화하는 방법 (이미 specilzied)? 예를 들어

template<unsigned number> 
struct A 
{ 
    template<class T> 
    static void Fun() 
    {} 
}; 

template<> 
struct A<1> 
{ 
    template<class T> 
    static void Fun() 
    { 
     /* some code here. */ 
    } 
}; 

그리고는 < 1> :: 재미()

template<> 
template<> 
void A<1>::Fun<int>() 
{ 
    /* some code here. */ 
} 

가 작동하지 않는 것을 전문으로하고 싶다. 그것을하는 방법? 감사.

답변

2

클래스 템플릿의 명시적인 특수화는 정규 클래스와 유사합니다 (완전히 인스턴스화되어 있으므로 매개 변수 유형이 아닙니다). 당신의 멤버 함수 Fun 함수 템플릿하지만 정규 멤버 함수 아니었다면

// template<> <== NOT NEEDED: A<1> is just like a regular class 
template<> // <== NEEDED to explicitly specialize member function template Fun() 
void A<1>::Fun<int>() 
{ 
    /* some code here. */ 
} 

마찬가지로, 당신은 전혀 template<>이 필요하지 않을 :

template<> 
struct A<1> 
{ 
    void Fun(); 
}; 

void A<1>::Fun() 
{ 
    /* some code here. */ 
} 
따라서 외부 template<> 필요하지 않습니다
+0

Splendid! 고마워요! – user1899020

+0

@ user1899020 : 도움이 되셨습니다. :) –