0
我想在golang中實現繼承。 下面是例子:使用golang中的繼承方法訪問對象
type A struct {
Number int
}
type B struct{
A
name String
}
func (a A) GetNumber() {
// Here I want to use instance of B
fmt.Println(a) // but this is giving me instance of A
}
是否有可能在A的函數來獲得B的情況下,如果A正在被B繼承?
Go中沒有繼承。一些相關/可能的重複:[one](http://stackoverflow.com/questions/21251242/is-it-possible-to-call-overridden-method-from-parent-struct-in-golang),[two] (http://stackoverflow.com/questions/30622605/can-embedded-struct-method-have-knowledge-of-parent-child),[三](http://stackoverflow.com/questions/29390736/go- embedded-struct-call-child-method-instead-parent-method),[four](http://stackoverflow.com/questions/29144622/what-is-the-idiomatic-way-in-go-to-create -的-結構-a複雜的層次結構)。 – icza