私はClang 3.0で次のコードをコンパイルしようとしていました。 リンクに失敗しました。ここで何か間違っているのですか、これはコンパイラのバグですか?
"__ZN9int_arrayIJLi0ELi1ELi2ELi3ELi4ELi5ELi6ELi7ELi8EEE4listE"、 から参照: __ZN9int_arrayIJLi0ELi1ELi2ELi3ELi4ELi5ELi6ELi7ELi8EEE5printEv CC-JDTbNl.oのLDにある:記号(S)アーキテクチャx86_64の静的配列intでの奇妙なリンカーエラー
エラーは、アーキテクチャx86_64のため
未定義シンボルを次
コードは次のとおりです。
#include <iostream>
static const int a[] = {0,1,2,3,4,5,6,7,8};
template<int... Numbers> struct int_array;
template<int... Numbers>
struct int_array {
int x;
const static int list[] = {Numbers...};
static void print() {
for (const int x : list) {
std::cout << x <<std::endl;
}
}
static void print2() {
for (const int x : a) {
std::cout << x <<std::endl;
}
}
};
typedef int_array<0,1,2,3,4,5,6,7,8> array_of_ints;
int main (int argc, const char * argv[])
{
array_of_ints::print();
array_of_ints::print2();
return 0;
}
私はクラス内の初期化は静的const * integral *メンバーのみに許可されていると思います。 –
ありがとうございました。私はこれをclangみんなにバグとして提出します – James
@KerekそれはC++ 03の状況でした。 C++ 11では、リテラルconst静的メンバーのクラス内初期化を行うことは問題ありません。 – Yuji