Is it possible to specialize a template using a member enum?

前端 未结 2 1525
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 05:44
struct Bar {
  enum { Special = 4 };
};

template struct Foo {};
template struct Foo {};

U

2条回答
  •  滥情空心
    2020-12-29 06:27

    The type of a non-type template argument cannot depend on a template parameter of a partial specialization.

    ISO C++03 14.5.4/9 says

    A partially specialized non-type argument expression shall not involve a template parameter of the partial specialization except when the argument expression is a simple identifier.

    template  struct A {};
    template  struct A {}; //error
    template  struct B {};
    template  struct B {};     //OK
    

    So something like this is illegal template struct Foo {}; because T::Special depends on T

    The usage is also illegal. You have provided one template argument but you need to provide two.

提交回复
热议问题