我有一个go结构,我需要使用其中一个字段。但是我开始使用字符串。我该怎么说才能获得这个领域。
package main
import "fmt"
func main() {
type Point struct{
x int
y int
}
pt := Point{x:2, y:3}
a := "x"
fmt.Printf("%s", pt.a)
}
自a = "x"
以来我期待pt.x = 2
。这是打印出来的错误信息。我肯定是从一个字符串开始,所以我不能删除引号。
$ go run point.go
# command-line-arguments
./point.go:14: pt.a undefined (type Point has no field or method a)