go

structの関数プロパティとメソッドの挙動

package main import "fmt" type OpFunc func(int, int) int type Operation struct { // associateされていないのでOperationのプロパティ・メソッドへのアクセスは出来ない。 Do1 OpFunc // 以下コメントを外すと "type Operation has both field and meth…

golangのType Assertionメモ

Type AssertionはC++のdynamic_cast的な機能。 interfaceを別の型にキャストする時に使用。 2通りの受け方がある。 package main import ( "fmt" "errors" ) type MyError struct { i int } func (e *MyError) Error() string { return fmt.Sprintf("i = %d"…