init block in struct

125 views Asked by At

I read this line from init Block https://wiki.gnome.org/Projects/Genie#init_Block

An init block declared outside of a class or struct is equivalent to a "main" function in C and only one of these may be present.

that say, we can declare an init block in class or struct.

Yes! We can write an init block in class, But how?

a construct works fine:

[indent=4]

struct Asd
    A: string
    construct()
        A = "123"

init
    var a = Asd ()
    print a.A

when I replace construct to init, it dosen't work!

How to write an init block in struct?

1

There are 1 answers

0
nemequ On

Get rid of the ().

See https://wiki.gnome.org/Projects/Genie#Constructors for an example.