"Go 포인터 리시버"의 두 판 사이의 차이

 
37번째 줄: 37번째 줄:
* https://go.dev/tour/methods/4
* https://go.dev/tour/methods/4


[[분류: Go]]
[[분류: Go OOP]]
[[분류: Go 포인터]]

2023년 5월 18일 (목) 09:54 기준 최신판

1 개요[ | ]

Go pointer receivers
Go 포인터 리시버
package main

import (
	"fmt"
	"math"
)

type Vertex struct {
	X, Y float64
}

func (v Vertex) Abs() float64 {
	return math.Sqrt(v.X*v.X + v.Y*v.Y)
}

func (v *Vertex) Scale(f float64) {
	v.X = v.X * f
	v.Y = v.Y * f
}

func main() {
	v := Vertex{3, 4}
	v.Scale(10)
	fmt.Println(v.Abs())
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}