Re: [Vala] static member variable intialization



Luca Bruno wrote:
Hi, it's not possible (at least for now) due to C limitations: see
https://bugzilla.gnome.org/show_bug.cgi?id=543189

However, a dummy instantiation before first static access should work:

class Statico : Object {

        public static int test_value;

        static construct {
                test_value = 5;
        }

        public static int get_test_value () {
                return test_value;
        }
}

void main () {
        new Statico ();
        stdout.printf ("%d\n", Statico.get_test_value ());
}


Best regards,

Frederik



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