Domanda

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

struct MyStruct {
    ubyte[] a = {1, 2, 3, 4}; // Will Fail
}
È stato utile?

Soluzione

Try square brackets:

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

Here is the syntax for array literals.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top