0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Go言語 構造体

Posted at

構造体

構造体とは、複数の任意の型を、1つの要素にまとめたもの。
さまざまなデータ構造を、1つの「型」として扱うことが可能。

Code

// 監督名のための共通化用構造体
type Directer struct {
	Name    string
	Country string
}

// 映画タイトルのための構造体
type Movie struct {
	Directer
	Title    string
	Year     int
}

// 受賞タイトルのための構造体
type Prise struct {
	Directer
	Title    string
	Year     int
}

// メイン関数
func main() {

	// スティーブン・スピルバーグ
	movie1 := Movie{
		Directer: Directer{"Steven Spielberg", "USA"},
		Title: "Saving Private Ryan",
		Year: 1998,
	}
	prise1 := Prise{
		Directer: Directer{"Steven Spielberg", "USA"},
		Title: "Academy Award for Directing",
		Year: 1998,
	}

	// 構造体の出力
	fmt.Println(movie1, prise1)
}

Output Sample

$ go build main.go
$ ./main
{{Steven Spielberg USA} Saving Private Ryan 1998} {{Steven Spielberg USA} Academy Award for Directing 1998}

GitHub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?