I have a struct A, extending ("subclassing") it with struct B, like this:
package main
type A struct {
x int
}
type B struct {
A
y int
}
I want to create a array where I can append A or B to it, so that this code works:
func main() {
var m [2]B
m[0] = B { A { 1 }, 2 }
m[0].x = 0
m[0].y = 0
m[1] = A { 3 }
m[1].x = 0
}
It doesn't. If I create the array of the type B, I get "cannot use struct literal (type A) as type B in assignment". If I try to create the array of the type A, I get the the same error (just with the types reversed).
So my question is: which type should the array be?