Re: [Vala] Vala 0.22.0 - requiring instance of Class to access Class class-members.
- From: Luca Bruno <lethalman88 gmail com>
- To: Thomas Olson <tolson stratagium net>
- Cc: Vala List <vala-list gnome org>
- Subject: Re: [Vala] Vala 0.22.0 - requiring instance of Class to access Class class-members.
- Date: Sun, 29 Sep 2013 18:36:11 +0200
I believe it's a bug in the compiler. It's non-sense to require an instance
when those are class-level instances.
However as a workaround you can use static fields. You can still initialize
them with class construct { } or static construct { }.
Also if you were thinking of overriding a protected class field, I hardly
believe that's implemented (there's a bug somewhere about that).
On Sun, Sep 29, 2013 at 5:58 PM, Thomas Olson <tolson stratagium net> wrote:
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<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
______________________________**_________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/**mailman/listinfo/vala-list<https://mail.gnome.org/mailman/listinfo/vala-list>
--
www.debian.org - The Universal Operating System
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]