我仍然在学习Golang,我想问一些问题。 是否有可能做这样的事情,并将任何其他孩子传递给扩展父结构的PM方法?如何调用父方法并传递在Golang中将父结构扩展为参数的任何子代
type Parent struct{
PAttribute string
}
func (p *Parent) PMethod(c *Child){
fmt.Println("this is parent Attribute : " + p.PAttribute)
fmt.Println("this is child Attribute : " + c.CAttribute)
}
type Child struct{
Parent
CAttribute string
}
type Child2 struct{
Parent
CAttribute string
}
func main(){
c := Child{
Parent{
"parent"
},
"child",
}
c.PMethod(&c)
c2 := Child2{
Parent{
"parent"
},
"child",
}
c2.PMethod(&c2)
}
谢谢
这是所有错误,可能是一个XY问题。停止考虑现在和永远的父/子对象层次结构,因为在这里__ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _没有明智的方法来模拟它。 – Volker
感谢您的建议,所以你有什么建议如何解决这个问题? –
没有问题描述jet。像“如果我点了啤酒,我怎么正确吃意大利面条?”不应答。 – Volker