부분 전문화를위한 정적 변수를 어떻게 초기화해야합니까?C++ 부분 템플릿 전문의 정적 변수를 초기화하는 방법
template <bool A=true, bool B=false>
struct from {
const static std::string value;
};
// no specialization - works
template <bool A, bool B>
const std::string from<A, B>::value = "";
// partial specialization - does not compile -
// Error: template argument list following class template name must list parameters in the order used in template parameter list
// Error: from<A,B>' : too few template arguments
template <bool B>
const std::string from<true, B>::value = "";
// full specialization - works
const std::string from<false, true>::value = "";
왜 부분 작동하지 않습니까?
편집 : 나는 나는 그것이 나 정적 변수를 초기화 할 수 전에 부분 특수화에 대한 선언을 반복해야 Partial template specialization for initialization of static data members of template classes
기반으로하는 솔루션을 발견 : 다시
template <bool B>
struct from<true, B> {
const static std::string value;
};
을, 질문은 왜 ?
어떤 컴파일러입니까? [g ++ 4.3.4] (http://ideone.com/jM6sIb)에서 마지막 하나가 작동하지 않습니다. – didierc
전체 클래스 템플릿을 전문화하지 않아도됩니까? 나는 명백한 (= 완전한) 전문화 만이 회원들에게 허용된다고 생각한다. –
컴파일러는 VS2010 –