How to automatically initialize a member array of a structure in D?

struct MyStruct {
    ubyte[] a = {1, 2, 3, 4}; // Will Fail
}
有帮助吗?

解决方案

Try square brackets:

struct MyStruct {
    ubyte[] a = [1, 2, 3, 4]; // Compiles
}

Here is the syntax for array literals.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top