specialize a member template without specializing its parent

前端 未结 4 1032
孤街浪徒
孤街浪徒 2020-12-17 20:56

I have a class template nested inside another template. Partially specializing it is easy: I just declare another template< … > block inside its parent.

4条回答
  •  既然无缘
    2020-12-17 21:24

    Complex stuff. Your initial code ICE's VC10 Beta2, nice.

    First off, I think you have this backwards:

    template<> 
    template< class X > 
    struct A< X >::B< int > {};
    

    X is a template param to struct A, and B is the one fully specialized, so I think it should be this:

    template< class X > 
    template<> 
    struct A< X >::B< int > {};
    

    But even this fails to compile. The error text is actually useful, though:

    a.cpp a.cpp(11) : error C3212: 'A::B' : an explicit specialization of a template member must be a member of an explicit specialization a.cpp(8) : see declaration of 'A::B'

    It looks like it is only legal to fully specialize B if you also fully specialize A.

    Edit: Ok, I heard back from someone who can speak authoritatively on this - to paraphrase, this is a very murky area in the standard, and it's an open issue with the C++ Committee to clean it up ("it" being explicit specializations of members of class templates). In the near term, the advice is "Don't do that".

提交回复
热议问题