v icon indicating copy to clipboard operation
v copied to clipboard

Embedding structs

Open tonylinyy opened this issue 7 years ago • 12 comments

sample code is: struct Point { x int y int }

struct Point3D { Point z int } it compile faild,just panic

tonylinyy avatar Apr 27 '19 12:04 tonylinyy

Embedding structs is not implemented yet.

medvednikov avatar Apr 27 '19 14:04 medvednikov

This feature may cause confusion

zaoqi avatar Apr 28 '19 15:04 zaoqi

This feature may cause confusion

Totally Agreed! Need some style to make it happen.

arhen avatar Apr 28 '19 15:04 arhen

It's one of the specs of Go.

1l0 avatar Apr 28 '19 15:04 1l0

So V is Go++?

zaoqi-unsafe avatar Apr 29 '19 07:04 zaoqi-unsafe

What if we have x in both 🤔😶. confusion Keeb V simple.

hamad-almamari avatar May 12 '19 00:05 hamad-almamari

Embedding works really well in Go and allows to migrate OOP code easier.

The name conflict is handled pretty easily:

https://play.golang.org/p/88nwQIsQIMK

medvednikov avatar May 12 '19 00:05 medvednikov

So V is Go++?

of course a better go or better c, but not go++.

ghost avatar May 14 '19 17:05 ghost

struct point {
    x int
    y int
}

struct point3d {
    p point
    z int
}

This is now the structure.

Bowero avatar Aug 27 '19 08:08 Bowero

@Bowero embedded structs are not implemented yet.

medvednikov avatar Aug 27 '19 09:08 medvednikov

Embedding works really well in Go and allows to migrate OOP code easier.

The name conflict is handled pretty easily:

https://play.golang.org/p/88nwQIsQIMK

Somehow this example looks wrong and I wonder why it compiles and how the second output value can be "0" (it is never assigned to A), in my view a correct example would look rather like: https://play.golang.org/p/8Qo6vzWs0px

gslicer avatar Aug 28 '19 07:08 gslicer

Closed. Struct embedding was (initially) implemented in https://github.com/vlang/v/commit/2c75b1397cbd8b940bdf357ebb74d59660c53f51.

nedpals avatar Nov 07 '20 01:11 nedpals