Source file tour/methods/indirection.go
1 //go:build OMIT 2 3 package main 4 5 import "fmt" 6 7 type Vertex struct { 8 X, Y float64 9 } 10 11 func (v *Vertex) Scale(f float64) { 12 v.X = v.X * f 13 v.Y = v.Y * f 14 } 15 16 func ScaleFunc(v *Vertex, f float64) { 17 v.X = v.X * f 18 v.Y = v.Y * f 19 } 20 21 func main() { 22 v := Vertex{3, 4} 23 v.Scale(2) 24 ScaleFunc(&v, 10) 25 26 p := &Vertex{4, 3} 27 p.Scale(3) 28 ScaleFunc(p, 8) 29 30 fmt.Println(v, p) 31 } 32