3
我与static constexpr
属性有一些困难:它与积分类型一起使用,有enum class
成员,但是当我尝试使用静态初始化的整数数组完成时,它失败链接说undefined reference to S::a
里面main
。C++ 14静态constexpr成员数组链接失败
这是与铿3.9或g ++ 6.3和ld 2.27.90;和所有与-std=c++14
。
这里是重现此最快的片段:
struct S
{
static constexpr int a[5] = {0};
};
int main()
{
S s{};
[[gnu::unused]] int b = s.a[0]; // force S stuff to be emitted
return 0;
}
谢谢您可能有这种情况的任何建议。
你需要定义你的对象;在命名空间范围:'constexpr int S :: a [5];' – ildjarn
@ildjarn谢谢!但是你知道为什么我必须为数组做这个而不是像纯整型类型的其他东西吗? – suut