在部分特化的模板中,需要使用外部定义的静态constexpr。可以通过将静态成员函数定义为模板函数来解决这个问题。以下是示例代码:
template
class Foo {
public:
static constexpr int value = 0;
};
template
constexpr int Foo::value;
template
class Foo {
public:
template
static constexpr int bar() {
return N;
}
};
int main() {
static_assert(Foo::bar<5>() == 5, "");
return 0;
}
在上面的示例中,模板类Foo定义了一个静态constexpr成员变量value。在部分特化的模板类Foo
下一篇:部分特化的模板作为模板参数