大家好,我是golang新人,碰到了一个语法级别问题,找了好多地方也没头绪,希望前辈指点:
目录结构:
```
/test
|
|--/demo
| |--demo.go
|--main.go
```
demo.go:
```go
package kz
type Order struct{
name String
}
```
```go
package main
import (
"fmt"
"./demo"
)
func main(){
var o kz.Order
o.name="kz"
fmt.Println(o)
o1 := kz.Order{name:"kz"}
fmt.Println(o1)
o2 := new(kz.Order)
o2.name="kz"
fmt.Println(o2)
}
```
不管哪种方法,编译失败:都提示:
```
$ go run main.go
# command-line-arguments
.\main.go:10:4: o.name undefined (cannot refer to unexported field or method name)
.\main.go:13:21: unknown field 'name' in struct literal of type kz.Order
.\main.go:17:5: o2.name undefined (cannot refer to unexported field or method name)
```
不知道是哪里没有理解?求解惑~谢谢~
更多评论