Box
の値をにダウンキャストする手作業で手書きでBox
にコピーしますか? (修飾されていない手段は、パッケージ名とオプションを省略ダウンキャストハイタイプからダウン
type Box struct {
Name string
}
type RatedBox struct {
Box
Points int
}
func main() {
rated := RatedBox{Box: Box{Name: "foo"}, Points: 10}
box := Box(rated) // does not work
}
// works, but is quite verbose for structs with more members
box := Box{Name: rated.Name}
を[Golang:異なる構造体タイプ間の変換は可能ですか?](https://stackoverflow.com/questions/24613271/golang) -is-conversion-between-different-struct-types-possible) –
使用できません。ボックス:= rated.Box ?? –
関連:https://stackoverflow.com/a/37725577/19020 –