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