modified: 18.1.md

new file:   18.10.md
	new file:   18.11.md
	new file:   18.2.md
	new file:   18.3.md
	new file:   18.4.md
	modified:   18.5.md
	new file:   18.6.md
	new file:   18.7.md
	new file:   18.8.md
	new file:   18.9.md
	modified:   directory.md
This commit is contained in:
songleo
2016-01-03 13:53:23 +08:00
parent 7ea77a4738
commit 7c06912c30
12 changed files with 417 additions and 75 deletions

34
eBook/18.4.md Normal file
View File

@@ -0,0 +1,34 @@
# 18.4 结构体
创建:
```go
type struct1 struct {
field1 type1
field2 type2
}
ms := new(struct1)
```
初始化:
```go
ms := &struct1{10, 15.5, "Chris"}
```
当结构体的命名以大写字母开头时,该结构体在包外可见。
通常情况下为每个结构体定义一个构建函数并推荐使用构建函数初始化结构体参考例10.2
```go
ms := Newstruct1{10, 15.5, "Chris"}
func Newstruct1(n int, f float32, name string) *struct1 {
return &struct1{n, f, name}
}
```
## 链接
- [目录](directory.md)
- 上一章:[运算符模板和接口](17.4.md)
- 下一节:[字符串](18.1.md)