docs: structs: custom default values
parent
789b75df92
commit
cd43258f41
14
doc/docs.md
14
doc/docs.md
|
@ -631,7 +631,8 @@ println(p.x)
|
||||||
The type of `p` is `&Point`. It's a reference to `Point`.
|
The type of `p` is `&Point`. It's a reference to `Point`.
|
||||||
References are similar to Go pointers and C++ references.
|
References are similar to Go pointers and C++ references.
|
||||||
|
|
||||||
V doesn't allow subclassing, but it supports embedded structs:
|
<p> </p>
|
||||||
|
|
||||||
|
|
||||||
```v
|
```v
|
||||||
// TODO: this will be implemented later
|
// TODO: this will be implemented later
|
||||||
|
@ -647,6 +648,17 @@ button.set_pos(x, y)
|
||||||
button.widget.set_pos(x,y)
|
button.widget.set_pos(x,y)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
V doesn't allow subclassing, but it supports embedded structs.
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
```v
|
||||||
|
struct Foo {
|
||||||
|
pos int = -1
|
||||||
|
x int // x is 0 by default
|
||||||
|
}
|
||||||
|
```
|
||||||
|
All struct fields are zeroed by default during the creation of the struct. But it's also possible to define custom default values.
|
||||||
|
|
||||||
## Access modifiers
|
## Access modifiers
|
||||||
|
|
||||||
Struct fields are private and immutable by default (making structs immutable as well).
|
Struct fields are private and immutable by default (making structs immutable as well).
|
||||||
|
|
Loading…
Reference in New Issue