Files
the-way-to-go_ZH_CN/eBook/18.4.md
songleo 830785f46e modified: eBook/18.10.md
modified:   eBook/18.3.md
	modified:   eBook/18.4.md
	modified:   eBook/18.5.md
	modified:   eBook/18.6.md
	modified:   eBook/18.7.md
	modified:   eBook/18.8.md
	modified:   eBook/18.9.md
2016-01-03 22:25:47 +08:00

700 B
Raw Blame History

18.4 结构体

创建:

type struct1 struct {
    field1 type1
    field2 type2
    
}
ms := new(struct1)

初始化:

ms := &struct1{10, 15.5, "Chris"}

当结构体的命名以大写字母开头时,该结构体在包外可见。 通常情况下,为每个结构体定义一个构建函数,并推荐使用构建函数初始化结构体(参考例10.2

ms := Newstruct1{10, 15.5, "Chris"}
func Newstruct1(n int, f float32, name string) *struct1 {
    return &struct1{n, f, name} 
}

链接