Template partial specialization

后端 未结 3 1836
不知归路
不知归路 2020-12-11 08:47

Would any one knows according to what rules code below doesn\'t compile?

template 
struct B
{
    typedef T type;
};

template

        
3条回答
  •  爱一瞬间的悲伤
    2020-12-11 08:59

    You need to use typename keyword as,

    template
    struct X::type*>
    {
    };
    

    It's because B::type is a dependent name. So typename is required!

    --

    EDIT:

    Even after putting typename, it isn't compiling. I think it's because deduction of type T in B from X is difficult, or possibly impossible, for the compiler. So I believe its non-deduced context.

    See a similar example here and the discussion:

    Template parameters in non-deduced contexts in partial specializations


    However, if you change the specialization to this:

    template
    struct X >
    {
    };
    

    Then it becomes the deducible context, and so would compile.

提交回复
热议问题