Content deleted Content added
Undid revision 1306725083 by 178.69.159.68 (talk), please discuss this on the talk page or Wikipedia:Copyright problems/2025 July 15 before reverting this |
Rewrite Structs and Heap structs examples from scratch with additional mention to initilization by name and by position as well as heap allocation via attribute. |
||
Line 83:
=== Structs ===
Struct example:<ref name="Knott"/><ref name="section"/>
<syntaxhighlight lang="
struct
name string
score f32
}
// Struct fields can be initialized by name
var1 := Foobar {
number: 21
name: "baz"
score: 2.5
}
// or by position
</syntaxhighlight>
=== Heap structs ===
Structs that are
<syntaxhighlight lang="
struct
}
@[heap]
struct Bar {
number f32
}
// Structs that are referenced are heap allocated
var1 := &Foo {2}
// Bar is always heap allocated because of its [heap] attribute
var2 := Bar{4.5}
</syntaxhighlight>
=== Methods ===
|