My question here is why the slice is empty in another func when the slice is global to the file?
Here's a piece of code:
package main
import "fmt"
type Vec3 struct {
x float32
y float32
z float32
}
var a []Vec3
func main() {
a := make([]Vec3, 0)
a = append(a, Vec3{2.0, 3.0, 4.0})
a = append(a, Vec3{3.4, 5.6, 5.4})
a = append(a, Vec3{6.7, 4.5, 7.8})
fmt.Printf("%+v
", a)
doSomethingWithA();
}
func doSomethingWithA() {
fmt.Printf("%+v
", a)
}
Output:
[{x:2 y:3 z:4} {x:3.4 y:5.6 z:5.4} {x:6.7 y:4.5 z:7.8}]
[]
This is a repl.it link too, if you want to take a look.
Thanks for your kind help.