This is a creation in Article, where the information may have evolved or changed.
struct struct
- The struct in Go is very similar to the struct in C, and go has no class
- define structure with type struct{}, name follows visibility rules
- Supports pointer-type members pointing to themselves
- Supports anonymous structures that can be used as members or define member variables
- Anonymous structures can also be used for map values
- Structure can be initialized with literal values
- Allows you to read and write struct members directly through pointers
- Members of the same type can perform direct copy assignment
- The = = and! = Comparison operators are supported, but not > or <
- Support for anonymous fields, essentially a field defined by a type name
- Embedded structure as anonymous field looks like inheritance, but not inherited
- You can use the anonymous field pointer
1234567891011121314151617181920212223242526272829 |
typeHumanstruct{Sexint}//Use combination//Similar inheritancetypeTeacherstruct{HumannamestringAgeint}typeStudentstruct{HumannamestringAgeint} func main() {A: = Teacher{name:"Joe", Age: +, Human:human{sex:0}}a: = Student{name:"Joe", Age: -, Human:human{sex:1}}a.name ="Joe2"A.age = -A.sex = -} |