在 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 值初始化数组元素然后调用该函数?