開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 10(keep it to yourself - Encapsulation and Embedding)、Exercise(295)の解答を求めてみる。
コード
~/go/src/headfirstgo/geo/coordinates.go
package geo
type Coordinates struct {
Latitude float64
Longitude float64
}
func (c *Coordinates) SetLatitude(latitude float64) {
c.Latitude = latitude
}
func (c *Coordinates) SetLongitude(longitude float64) {
c.Longitude = longitude
}
sample1.go
package main
import (
"fmt"
"headfirstgo/geo"
)
func main() {
coordinates := geo.Coordinates{}
coordinates.SetLatitude(37.42)
coordinates.SetLongitude(-122.08)
fmt.Println(coordinates)
}
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go run sample1.go
{37.42 -122.08}
$
0 コメント:
コメントを投稿