1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: fix embedding example (#6804)

This commit is contained in:
Nick Treleaven 2020-11-12 12:50:37 +00:00 committed by GitHub
parent 9c569246ef
commit 21af7004ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1078,16 +1078,25 @@ References are similar to Go pointers and C++ references.
V doesn't allow subclassing, but it supports embedded structs:
```v
struct Widget {
mut:
x int
y int
}
struct Button {
mut:
Widget
title string
}
button := new_button('Click me')
button.set_pos(x, y)
mut button := Button{title: 'Click me'}
button.x = 3
```
Without embedding we'd have to name the `Widget` field and do:
// Without embedding we'd have to do
button.widget.set_pos(x,y)
```v oksyntax
button.widget.x = 3
```
### Default field values