Content deleted Content added
Small code snippets are not protected by copyright (especially common and simplistic small examples). Undid revision 1300654243 by Jan200101 (talk) |
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 |
||
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==
|