You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
)
type Node struct {
name string
}
type Nodes []*Node
type Graph struct {
nodes Nodes
}
func main() {
var graph Graph
var s *string
graph.nodes = Nodes{&Node{"hello"}, &Node{"world"}, &Node{"foo"}, &Node{"bar"}, &Node{"baz"}}
for i, n := range graph.nodes {
if i == 2 {
s = &n.name // foo.go:23:9: exporting a pointer for the loop variable n
}
}
fmt.Println(*s)
}
This is valid code because n takes new pointer values, so &n.name points correctly to different names.
The text was updated successfully, but these errors were encountered:
This is valid code because
n
takes new pointer values, so&n.name
points correctly to different names.The text was updated successfully, but these errors were encountered: