如何创建使用默认值初始化的结构?

How to create a structure initialized with default values?

如何创建一个已经有默认值的结构体? 有点像这样:

struct First {
    int data = 4;
    int pos = 5;
    }

void main () {
    var a = First ();
    assert(a.data == 4);
}

AlThomas 的回复:

"Structs in Vala can have initializers (similar to a constructor for a class) and methods. So what I can extract from your second pastebin you could write that as:"

struct First {
    int data;
    int pos;

    public First (int[] mass) {
        data= 5;
        pos = mass.length;
    }

    public int sas () {
        return data + pos;
    }
}

void main () {
    int[] a = {1,3,0,1,2,3,2,1};
    var b = First (a);
    print (@"$(b.sas ())\n");
}