我在使用
以下是最快的重现此问题的代码片段:
感谢您对这种情况提出的任何建议。
static constexpr
属性时遇到了一些困难:它可以与整数类型和 enum class
成员一起使用,但当我尝试使用一个静态初始化的整数数组时,链接时会失败,并在 main
中显示 undefined reference to S::a
。
这是使用 clang 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