[Vala] Inheritance of static members



Hello! I would like to know if in Vala a subclass can inherit static members
from its superclass. According to documentation, it should be possible to do
that (or, at least, I didn't find any explicit prohibition). However, valac
refuses to compile the code below:

class Base : GLib.Object {
    public static int F = 20;

    public static int P { get; set; default = 10; }

    public static void SM() {
        stdout.printf("Static method\n");
    }

    public void M() {
        stdout.printf("Method\n");
    }
}

class Derived : Base {
    // Empty
}

int main() {
    Base b = new Base();
    Derived d = new Derived();

    b.M();
    d.M();

    stdout.printf("Base.F = %d\n", Base.F); // = 20
    stdout.printf("Base.P = %d\n", Base.P); // = 10
    Base.SM();

    // valac doesn't like next three lines...

    stdout.printf("Derived.F = %d\n", Derived.F); // = 20
    stdout.printf("Derived.P = %d\n", Derived.P); // = 10
    Derived.SM();

    return 0;
}

In particular, valac (version 0.9.8) outputs this:

test.vala:32.36-32.44: error: The name `F' does not exist in the context of
`Derived'
    stdout.printf("Derived.F = %d\n", Derived.F); // = 20
                                      ^^^^^^^^^
test.vala:33.36-33.44: error: The name `P' does not exist in the context of
`Derived'
    stdout.printf("Derived.P = %d\n", Derived.P); // = 10
                                      ^^^^^^^^^
test.vala:34.2-34.11: error: The name `SM' does not exist in the context of
`Derived'
    Derived.SM();
    ^^^^^^^^^^

Thank you very much for any answer you can give. Bye, Alessio


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