go - Pointer within a custom structure -
recently, got exposed following source code "go programming blueprints" book.
type googlegeometry stuct { *googlelocation `json:"location"` } type googlelocation struct { lat float64 `json:"lat"` lng float64 `json:"lng"` }
what don't understand why googlegeometry structure uses pointer instead of literal, , reason behind such declaration?
i expect below declaration instead of pointer.
type googlegeometry stuct { gl googlelocation `json:"location"` }
i suppose because location
can null
or absent @ all.
such cases can represented pointers. because if literal have default values lat
, lng
.
please take on example: why pointer?
and value type instead of reference: value types have default values
Comments
Post a Comment