C# では、関数を使用して静的配列を生成できます。
private static readonly ushort[] circleIndices = GenerateCircleIndices();
....
private static ushort[] GenerateCircleIndices()
{
ushort[] indices = new ushort[MAXRINGSEGMENTS * 2];
int j = 0;
for (ushort i = 0; i < MAXRINGSEGMENTS; ++i)
{
indices[j++] = i;
indices[j++] = (ushort)(i + 1);
}
return indices;
}
C++ を使用すると、静的配列を生成する正しい方法は次のようになります。
.h
static const int BOXINDICES[24];
.cpp (コンストラクター)
static const int BOXINDICES[24] =
{
0, 1, 1, 2,
2, 3, 3, 0,
4, 5, 5, 6,
6, 7, 7, 4,
0, 4, 1, 5,
2, 6, 3, 7
};
circleIndices に対して同じことを行うにはどうすればよいですか?関数を使用して値を生成するにはどうすればよいですか?
.h
static const int CIRCLEINDICES[];
.cpp (コンストラクター)
static const int CIRCLEINDICES[] = GenerateCircleIndices(); // This will not work
配列要素を値 0 で初期化してから関数を呼び出す必要がありますか?