dsa89029 2014-08-27 02:01
浏览 58
已采纳

无法引用未导出的名称m.β

Have a look at these two simple packages:

package m
const β = 1
package main
import ("m";"fmt")
func main() {
    fmt.Println(m.β)
}

I get this error when I try to compile them:

$ GOPATH=`pwd` go run a.go 
# command-line-arguments
./a.go:4: cannot refer to unexported name m.β
./a.go:4: undefined: m.β

Why? I tried replacing the β with B in both packages, and it works, but I'm trying to use the proper symbol here. Maybe both packages are using homoglyphs or different encodings for some reason?

  • 写回答

4条回答 默认 最新

  • doucheyi1347 2014-08-27 02:05
    关注

    The go specifications say that an identifier is exported if

    the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu")

    https://golang.org/ref/spec#Exported_identifiers

    func main() {
        fmt.Println(unicode.IsUpper('β'))
    }
    

    returns

    false
    

    http://play.golang.org/p/6KxF5-Cq8P

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器