vendredi 10 avril 2015

How to make this golang abstract struct work?


Vote count:

0




Code



func main() {
t7()
}
type (
IA interface {
A()
B()
}
AbsA struct {IA }
CA struct {
AbsA
}
)
func (a AbsA)A(){
fmt.Println("Show A")
a.B()
}
func (a CA)B(){
fmt.Println("Show B")
}
func t7(){
var a IA
a = CA{}
a.A()
}


Run this will get nil pointer, because when AbsA call B() func, it will use the embedded IA, but IA is an interface.


Is there any way to make this works ?



asked 38 secs ago

wener

874






How to make this golang abstract struct work?

Aucun commentaire:

Enregistrer un commentaire