Content deleted Content added
Rescuing 0 sources and tagging 1 as dead.) #IABot (v2.0.9.5 |
Small code snippets are not protected by copyright (especially common and simplistic small examples). Undid revision 1300654243 by Jan200101 (talk) |
||
Line 83:
=== Structs ===
Struct example:<ref name="Knott"/><ref name="section"/>
<syntaxhighlight lang="V">
Line 100 ⟶ 99:
assert p.a == 15
</syntaxhighlight>
=== Heap structs ===
Structs are allocated on the stack by default. The {{code|&}} prefix can be used, for getting a reference to it and allocating on the heap instead:{{sfn|Rao|2021}}
<syntaxhighlight lang="V">
Line 115 ⟶ 112:
println(p.a)
</syntaxhighlight>
=== Methods ===
Line 122 ⟶ 118:
The is_registered method has a receiver of type User named u. The convention is not to use receiver names like self or this, but preferably a short name. For example:<ref name="Knott"/><ref name="nasufi"/>
<syntaxhighlight lang="V">
struct User {
Line 142 ⟶ 137:
println(user2.is_registered()) // "true"
</syntaxhighlight>
=== Error handling ===
Optional types are for types which may represent none. Result types may represent an error returned from a function.
Line 163 ⟶ 156:
</syntaxhighlight>
==See also==
|