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

(새 문서: ==개요== ;Go pointer receivers ;Go 포인터 리시버 <syntaxhighlight lang='go' run> package main import ( "fmt" "math" ) type Vertex struct { X, Y float64 } func (v Vertex)...)
 
31번째 줄: 31번째 줄:


==같이 보기==
==같이 보기==
* [[Go 포인터]]
* [[Go 리시버]]
* [[Go 리시버]]



2023년 4월 5일 (수) 02:26 판

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 }}