Struct 无法在编译时读取结构枚举

Struct 无法在编译时读取结构枚举,struct,enums,d,dmd,Struct,Enums,D,Dmd,我有一个结构枚举,我使用它的值来定义数组大小;然而,编译器抱怨结构的值在编译时是未知的 module main; struct Point3D { ubyte x; ubyte y; ubyte z; } void main() { enum Point3D point = {x:1, y:1, z:1}; int testArray[point.x][point.y][point.z]; // ERRORS -

我有一个结构枚举,我使用它的值来定义数组大小;然而,编译器抱怨结构的值在编译时是未知的

module main;

struct Point3D {
        ubyte x;
        ubyte y;
        ubyte z;
}

void main() {
        enum Point3D point = {x:1, y:1, z:1};
        int testArray[point.x][point.y][point.z]; // ERRORS - X Cannot be read at compile time. 
}

编译器告诉我它不能在编译时读取x(它甚至告诉我4次)。这是为什么?

看起来像是一个编译器错误。。。您可以通过将值保存到中间枚举来解决此问题:

enum Point3D!ubyte BlobSize = {x:32, y:32, z:32};
enum BlobX = BlobSize.x;
enum BlobY = BlobSize.y;
enum BlobZ = BlobSize.z;
blobcontents[BlobX][BlobY][BlobZ] data;

你的例子似乎确实管用。奇怪的是,它无法读取数组中的结构内容,但可以读取数组外部的结构内容。