You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
641 B
Go
36 lines
641 B
Go
1 year ago
|
// Aggregated Datatype
|
||
|
// Groups together objects of arbitray types into one object
|
||
|
// No inheritance!
|
||
|
// Straight from C
|
||
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
type Person struct {
|
||
|
name string
|
||
|
addr string
|
||
|
phone string
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
// Empty
|
||
|
var p1 Person
|
||
|
fmt.Println(p1)
|
||
|
p1.name = "Drew"
|
||
|
p1.addr = "123 Fake Street"
|
||
|
p1.phone = "8675309"
|
||
|
fmt.Println(p1)
|
||
|
|
||
|
// Literal
|
||
|
p2 := Person{"Margot", "123 Fake Street", "8675309"}
|
||
|
fmt.Println(p2)
|
||
|
|
||
|
// Other literal
|
||
|
p3 := Person{name: "Harri", addr: "123 Fake Street", phone: "8675309"}
|
||
|
fmt.Println(p3)
|
||
|
|
||
|
// New func, returns a pointer to the
|
||
|
p4 := new(Person)
|
||
|
fmt.Println(*p4) //derefence
|
||
|
}
|