是否可以将contexpr值传递给构造函数?

时间:2019-05-27 21:50:11

标签: c++ templates constructor c++17

有什么方法可以将编译时常量值传递给构造函数而不使其成为类模板参数?

该语言不允许您将显式模板参数传递给构造函数,非类型模板参数必须是显式的。

struct Foo {
    template <int N>
    Foo() { bar<N>(); }
};

int main() {
    Foo<5> f{};  // error: 'Foo' is not a template
}

0 个答案:

没有答案