Given the following types:
type (
Parent struct {
name string
surname string
}
Child struct {
*Parent
sport String
}
)
...
func (p *Parent) GetSport() string {
return ((*Child)(p)).sport // does not work
}
How do I convert *Parent
to *Child
?
func (p *Parent) Convert() *Child {
return &Child{p, ""}
}
https://play.golang.org/p/saGvRu_rIk
The problem is there’s no data about sport
. So we have to put empty line.