Advertisement
Koepnick

structs

Jan 15th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.46 KB | None | 0 0
  1. // Just a collection of fields
  2. type Somename struct{
  3.     a int
  4.     b int
  5.     c, d string
  6. }
  7. ...
  8. // Explicit instantiation
  9. var s = Somename{3, 4, "c", "d"}
  10. // Access the fields with dot notation
  11. s.b = 10
  12. // Access to fields via pointers is implicit
  13. p := &s
  14. p.c = "Pointed"
  15. fmt.Println(s)       // {3 10 pointed d}
  16. // Variables can be named during instantiation
  17. // This allows for implicit defaults
  18. t := Somename{b: 17, c:"Set"}
  19. fmt.Println(t)       // {0 17 Set  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement