Content deleted Content added
m Typo |
some syntax sections appear to be copied without proper attribution from the V documentation without proper attribution, editor Wukuendo disputes this so a copyright problem is reported to resolve this. Tags: Reverted 2017 wikitext editor |
||
Line 83:
=== Structs ===
{{Copyvio|timestamp=20250715164557 |url=https://docs.vlang.io/structs.html}}
Struct example:<ref name="Knott"/><ref name="section"/>
<syntaxhighlight lang="V">
Line 99 ⟶ 100:
assert p.a == 15
</syntaxhighlight>
</div>
=== Heap structs ===
{{Copyvio|timestamp=20250715164557 |url=https://docs.vlang.io/structs.html#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 112 ⟶ 115:
println(p.a)
</syntaxhighlight>
</div>
=== Methods ===
Line 118 ⟶ 122:
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"/>
{{Copyvio|timestamp=20250715164557 |url=https://docs.vlang.io/structs.html#methods}}
<syntaxhighlight lang="V">
struct User {
Line 137 ⟶ 142:
println(user2.is_registered()) // "true"
</syntaxhighlight>
</div>
=== Error handling ===
{{Copyvio|timestamp=20250715164557 |url=https://docs.vlang.io/type-declarations.html#optionresult-types-and-error-handling}}
Optional types are for types which may represent none. Result types may represent an error returned from a function.
Line 156 ⟶ 163:
</syntaxhighlight>
</div>
==See also==
|