From 21af7004ffbf95979376a09ea09778819fa51e7d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 12 Nov 2020 12:50:37 +0000 Subject: [PATCH] doc: fix embedding example (#6804) --- doc/docs.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 580cd0afe1..8a10c8b9b6 100644 --- a/doc/docs.md +++ b/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 +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