Created
December 28, 2014 15:48
-
-
Save sugilog/aa80ba3457a182ee991c to your computer and use it in GitHub Desktop.
構造体
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Space struct { | |
X int | |
Y int | |
Z int | |
} | |
type Planet struct { | |
Name string | |
Location Space | |
Status bool | |
} | |
func main() { | |
putPlanet() | |
putEmpty() | |
withPointer() | |
// withNew() | |
} | |
func putPlanet() { | |
space := Space{ 12, 24, 0 } | |
space.Z = 36 | |
planet := Planet{ Name: "Moon", Location: space, Status: true } | |
fmt.Println( "Space:", space ) | |
fmt.Println( "Planet:", planet ) | |
} | |
func putEmpty() { | |
space := Space{} | |
planet := Planet{} | |
fmt.Println( "Space:", space ) | |
fmt.Println( "Planet:", planet ) | |
} | |
func withPointer() { | |
space1 := Space{} | |
space2 := &space1 | |
space2.Z = 12345 | |
fmt.Println( "Space:", space1 ) | |
fmt.Println( "Space:", space2 ) | |
} | |
// func withNew() { | |
// var space *Space = new( Space ) | |
// planet := Planet{ Name: "Mars", Location: space } | |
// fmt.Println( "Space:", space ) | |
// fmt.Println( "Planet:", planet ) | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment