mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-19 03:50:11 +08:00
modified: eBook/18.1.md
modified: eBook/18.11.md modified: eBook/18.2.md modified: eBook/18.3.md modified: eBook/18.4.md modified: eBook/18.8.md
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# 18.4 结构体
|
||||
|
||||
创建:
|
||||
|
||||
创建:
|
||||
```go
|
||||
type struct1 struct {
|
||||
field1 type1
|
||||
@@ -11,14 +10,13 @@ type struct1 struct {
|
||||
ms := new(struct1)
|
||||
```
|
||||
|
||||
初始化:
|
||||
|
||||
初始化:
|
||||
```go
|
||||
ms := &struct1{10, 15.5, "Chris"}
|
||||
```
|
||||
|
||||
当结构体的命名以大写字母开头时,该结构体在包外可见。
|
||||
通常情况下,为每个结构体定义一个构建函数,并推荐使用构建函数初始化结构体(参考例10.2):
|
||||
当结构体的命名以大写字母开头时,该结构体在包外可见。
|
||||
通常情况下,为每个结构体定义一个构建函数,并推荐使用构建函数初始化结构体(参考例10.2):
|
||||
|
||||
```go
|
||||
ms := Newstruct1{10, 15.5, "Chris"}
|
||||
|
Reference in New Issue
Block a user