Mastering-Go-Second-Edition/ch07/methods.go
2019-01-10 22:09:57 +02:00

27 lines
420 B
Go

package main
import (
"fmt"
)
type twoInts struct {
X int64
Y int64
}
func regularFunction(a, b twoInts) twoInts {
temp := twoInts{X: a.X + b.X, Y: a.Y + b.Y}
return temp
}
func (a twoInts) method(b twoInts) twoInts {
temp := twoInts{X: a.X + b.X, Y: a.Y + b.Y}
return temp
}
func main() {
i := twoInts{X: 1, Y: 2}
j := twoInts{X: -5, Y: -2}
fmt.Println(regularFunction(i, j))
fmt.Println(i.method(j))
}