V: Embedding structs

Created on 27 Apr 2019  路  12Comments  路  Source: vlang/v

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

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

Feature Request

Most helpful comment

This feature may cause confusion

All 12 comments

Embedding structs is not implemented yet.

This feature may cause confusion

This feature may cause confusion

Totally Agreed! Need some style to make it happen.

It's one of the specs of Go.

So V is Go++?

What if we have x in both 馃馃樁.
confusion
Keeb V simple.

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

So V is Go++?

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

struct point {
    x int
    y int
}

struct point3d {
    p point
    z int
}

This is now the structure.

@Bowero embedded structs are not implemented yet.

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aurora picture aurora  路  3Comments

clpo13 picture clpo13  路  3Comments

markgraydev picture markgraydev  路  3Comments

cjmxp picture cjmxp  路  3Comments

PavelVozenilek picture PavelVozenilek  路  3Comments