类型内嵌和结构体内嵌
package main
import "fmt"
type Test struct {
int
bool
string
}
func main() {
test := Test{
10, //实际上 是 int:10
false,
"asas",
}
fmt.Println(test)
}
声明结构体内嵌
结构内嵌特性
声明
最后更新于
package main
import "fmt"
type Test struct {
int
bool
string
}
func main() {
test := Test{
10, //实际上 是 int:10
false,
"asas",
}
fmt.Println(test)
}
最后更新于
package main
import "fmt"
type BasicColor struct {
R,G,B float32
}
type Colors struct {
//结构体内嵌
BasicColor
Alpha float32
}
func main() {
//col := new(Color)
var col Colors
col.R = 222
col.G = 223
col.B = 224
fmt.Println(col)
col.Alpha = 2
fmt.Println(col)
}
c := Colors{
BasicColor:BasicColor{
R:23,
G:24,
B:25,
},
}
fmt.Println(c)