mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
doc: document that struct fields can now use keywords as their names (#23564)
This commit is contained in:
parent
a44ff7813a
commit
b0d2eeea5d
1 changed files with 15 additions and 0 deletions
15
doc/docs.md
15
doc/docs.md
|
@ -2408,6 +2408,21 @@ p = Point{10, 20}
|
||||||
assert p.x == 10
|
assert p.x == 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Struct fields can re-use reserved keywords:
|
||||||
|
|
||||||
|
```v
|
||||||
|
struct Employee {
|
||||||
|
type string
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
employee := Employee{
|
||||||
|
type: 'FTE'
|
||||||
|
name: 'John Doe'
|
||||||
|
}
|
||||||
|
println(employee.type)
|
||||||
|
```
|
||||||
|
|
||||||
### Heap structs
|
### Heap structs
|
||||||
|
|
||||||
Structs are allocated on the stack. To allocate a struct on the heap
|
Structs are allocated on the stack. To allocate a struct on the heap
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue