Go Structs: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 6: | Line 6: | ||
A <tt>struct</tt> is a user-defined type that contains named fields. | A <tt>struct</tt> is a user-defined type that contains named fields. | ||
<font color=red>Are all users can define (in terms of types) structs, or there are other user-defined types?</font> | |||
=Definition= | =Definition= | ||
Line 28: | Line 30: | ||
</pre> | </pre> | ||
< | =Initialization= | ||
==Default Initialization== | |||
==<tt>new()</tt>== | |||
==Short variable == | |||
=Struct Literals= | =Struct Literals= |
Revision as of 02:04, 30 March 2016
Internal
Overview
A struct is a user-defined type that contains named fields.
Are all users can define (in terms of types) structs, or there are other user-defined types?
Definition
The struct type definition is introduced by the type keyword, to indicated that this is a user-defined type, followed by the type name and the keyword struct. Each field has a name and a type.
type myStruct struct { i int s string }
Fields with the same types can be collapsed:
type myStruct struct { ... i, j, k int ... }
Initialization
Default Initialization
new()
Short variable
Struct Literals
Fields
A field is always exported by the package it is enclosed in.