doc: fix embedding example (#6804)
parent
9c569246ef
commit
21af7004ff
17
doc/docs.md
17
doc/docs.md
|
@ -1078,16 +1078,25 @@ References are similar to Go pointers and C++ references.
|
||||||
V doesn't allow subclassing, but it supports embedded structs:
|
V doesn't allow subclassing, but it supports embedded structs:
|
||||||
|
|
||||||
```v
|
```v
|
||||||
|
struct Widget {
|
||||||
|
mut:
|
||||||
|
x int
|
||||||
|
y int
|
||||||
|
}
|
||||||
|
|
||||||
struct Button {
|
struct Button {
|
||||||
|
mut:
|
||||||
Widget
|
Widget
|
||||||
title string
|
title string
|
||||||
}
|
}
|
||||||
|
|
||||||
button := new_button('Click me')
|
mut button := Button{title: 'Click me'}
|
||||||
button.set_pos(x, y)
|
button.x = 3
|
||||||
|
```
|
||||||
|
Without embedding we'd have to name the `Widget` field and do:
|
||||||
|
|
||||||
// Without embedding we'd have to do
|
```v oksyntax
|
||||||
button.widget.set_pos(x,y)
|
button.widget.x = 3
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default field values
|
### Default field values
|
||||||
|
|
Loading…
Reference in New Issue