2013/3/16 Albert Hopkins <[email protected]>

> I'm trying to understand why class constructors are not being called.
> According to the docs:
>
> class-class-constructor-declaration:
>         class construct { statement-list }
> This block will be executed once at the first use of its class, and once
> at the first use of each subclass of this class.
>
> But in the following code, the "class construct" block is never fired"
>
> class MyClass: Object {
>
>     class construct {
>         // class constructor
>         stdout.printf("Hello world\n");
>     }
>
>     public static void noop() {
>     }
> }
>
> void main() {
>     MyClass.noop();
> }
>
> Either I'm doing something wrong, or I'm not understanding.  Shouldn't
> "Hello world" be printed once sometime before .noop() is called?
> Instead it's not printed at all.
> _______________________________________________
> vala-list mailing list
> [email protected]
> https://mail.gnome.org/mailman/listinfo/vala-list
>

Hi,

Your function 'noop()' is declared static, hence no instance is required to
call it.
Class constructors are called on the first construction of an instance, ie.
when you do 'new MyClass();' .

Jonas
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to