知识卡片
结构体聚合具名字段
struct把若干具名字段聚合为一个值,零值由各字段零值组成。字面量可按位置或字段名赋值,使用字段名能更清楚地对应含义;点号读取和修改字段,对结构体指针也可自动解引用后访问。结构体值本身与可能为nil的结构体指针要区分。
语法示例:type User struct { Name string };u := User{Name: "A"}。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Go Language Foundations · 查看原书依据
a struct is nothing more than an aggregation of zero or more fields as a single entity, where each field is a named value of an arbitrary type. A struct can be defined using the following type Name struct syntax. A struct is never nil: rather, the zero value of a struct is the zero
参考来源
- 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml)
- 结论依据:struct把若干具名字段聚合为一个值,零值由各字段零值组成。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:a struct is nothing more than an aggregation of zero or more fields as a single entity, where each field is a named value of an arbitrary type. A struct can be defined using the following type Name struct syntax. A struct is never nil: rather, the zero value of a struct is the zero