package main
import (
"fmt"
"math"
)
type Vertex struct {
X, Y float64
}
func (v Vertex) Scale(f float64) {
v.X = v.X * f
v.Y = v.Y * f
}
func (v Vertex) Abs() float64 {
return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
func main() {
v := &Vertex{3, 4}
fmt.Println(v.X)
fmt.Println(v.Abs())
}
Here is my code: for v := &Vertex{3, 4}
, v
is a pointer which point to Vertex{3, 4}
, but i find fmt.Println(v.X)
is ok for v := Vertex{3, 4}
or v := &Vertex{3, 4}
, also for function func (v Vertex) Abs() float64
which is used for Vertex
type, but using * Vertex
type to call it is also ok.
what's the reason?