定义结构体
struct
创建结构体
type Color struct{
R,G,B int
}实例化结构体——为结构体分配内存并初始化
var c Color
c.R = 255
d := Color{255,255,2255}创建指针类型的结构体
c := new(Color)
fmt.Println(c) //&{0 0 0}取结构体的地址实例化
最后更新于
struct
type Color struct{
R,G,B int
}var c Color
c.R = 255
d := Color{255,255,2255}c := new(Color)
fmt.Println(c) //&{0 0 0}最后更新于
d:=&Color{} // 这里被实例化了
fmt.Println(d) //&{0 0 0}