[Vala] Vala 0.22.0 - requiring instance of Class to access Class class-members.





Hello,

This is the second time I've tried to post to the list, but I haven't seen my first attempt show up in the vala-list archive yet, so I thought I would resend, just in case.

I'm still learning my way around vala so I may be doing something wrong, but according to the docs at https://wiki.gnome.org/Vala/Manual/Classes:

 * Class members are shared between all instances of a class. They can
   be accessed without an instance of the class, and class methods will
   execute in the scope of the class.


This does not appear to be the case. In the following example I cannot access the prop method of the Parent or Child classes without instantiating an instance of those classes.

public class Parent : Object {
    protected class int _prop;
    public class int prop() { return _prop; }
    class construct {
        _prop = 0;
    }
}

public class Child : Parent {
    class construct {
        _prop = 1;
    }
}

Parent p = new Parent();
print ("Parent.prop: %d\n", p.prop());         // Works as expected
print ("Parent.prop: %d\n", Parent.prop()); // error: Access to instance member `Parent.prop' denied

Child c = new Child();
print ("Child.prop: %d\n", c.prop());        // Works as expected
print ("Child.prop: %d\n", Child.prop()); // error: The name `prop' does not exist in the context of `Child'

Is this the desired behavior or are class methods, suppose to only be accessible from class instances?

Kind Regards,

Tom




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