Re: [Vala] initializing structures



more fun with structure initialization ....

I can't figure out how to initialize a structure that is class scope.
Does anyone have suggestions how to do this, or another way to
accomplish this?

using GLib;

public struct mystruct {
    public string test1;
    public int test2;
}

public class TestStruct : Object {
    public mystruct ms;
    public mystruct[] ms_array;

    public void init()
    {
        ms = mystruct() {test1="this is a test", test2=10};

        /* the following does not compile */
        ms_array = {
            mystruct() {test1="this is a test", test2=10},
            mystruct() {test1="this is a test", test2=20}
        };

        /* the following works */
        mystruct[] ms_array2 = {
            mystruct() {test1="this is a test", test2=10},
            mystruct() {test1="this is a test", test2=20}
        };

    }
}

-- 
=======================
Cliff Brake
http://bec-systems.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]