golang学习遭遇错误原因分析续
7、 error: reference to field ‘Printf’ in object which has no fields or methods
f.Printf("%v", (Map(f,m)))
问题点:
在启用import f "fmt"后,如果再在函数中定义变量f时,如果使用f.Print**,这就会出现上述错误了。
8、error: argument 1 has incompatible type (cannot use type int64 as type time.Duration)
time.Sleep(sec*1e9)
^
问题点:
Sleep的参数不正确,应该使用time.Duration进行类型转换。尽管time.Duration类型是使用type Duration int64方式定义的。
这个需要使用time.Duration(sec)进行转换才能编译正确的。
9、error: invalid break label ‘L’
break L
^
在使用 break 标签 时,需要将标签放在for语句之前,否则爆此错。
L: for ..;..;..{
if .. {
break L
}
}
10、fatal error: all goroutines are asleep - deadlock!
goroutine 1 [select]:
main.func_select
/home/niujie/workspace/go/src/study/go_reserved.go:364
main.main
/home/niujie/workspace/go/src/study/go_reserved.go:398
exit status 2
如下方式调用,则会出现上述错误:
for{
Loop:
f.Println("i is:", i)
select{
case <-c:
i++
if i>1{
goto Loop
}
}
}
正确的方法如下:
L: for{
f.Println("i is:", i)
select{
case <-c:
i++
if i>1{
break L
}
}
}
11、./go_study.go:6:8: error: imported and not used: sort_method
"./sort"
^
问题点:
这是导入自定义包时,名字不一致。也即:包的文件名字,与文件中package 包名 不一致。
我们在import时,需要按照文件中的package 包名,才可以。
12、 go_study.go:5:2: cannot find package "mysort" in any of:
/usr/local/go/src/pkg/mysort (from $GOROOT)
/home/niujie/workspace/go/src/mysort (from $GOPATH)
问题点:
在导入包后,golang会到GOROOT和GOPATH中搜索 包名 的路径。如果名字不同,会提示找不到包。
13、error: invalid reference to unexported identifier ‘mysort.bubble_sort’
mysort.bubble_sort(n)
^
问题点:
在包中函数,如果函数名首字母不是大写,那么该包是不会被导出的。所以,在定义需要导出函数时,
需要将函数首字母大写。
• 公有函数的名字以大写字母开头;
• 私有函数的名字以小写字幕开头。
最新文章
- C语言猜拳游戏
- 【亚瑟士 ASICS 系列】
- Request和Response对象
- Linux 2.6内核Makefile浅析
- java protected 与默认权限的区别
- 不能使用tpcc-mysql测试OneProxy
- Python计算斗牛游戏的概率
- 一个 C# 获取高精度时间类(调用API QueryP*)
- autocommit=0
- asp.net网站性能优化2则
- DropDownList绑定数据
- Android内存管理
- HDFS概述(6)————用户手册
- Linux下passwd和shadow文件内容详解
- bootstrap table dataView展开行详情,p元素自动换行
- Docker容器Tomcat部署war包
- Echarts . 在柱状图中添加自定义值 (键值对)
- 收藏:解决其它程序与IIS共享80端口的四个方法
- ql.io来自ebay的api快速集成的构建api的框架
- c++中的stl
热门文章
- POJ 3270 Cow Sorting(置换群)
- 【转】Dr.com 5.20破解教程
- Spring多资源文件properties的配置
- linux上tomcat安装
- Linux中断(interrupt)子系统
- loadrunner使用system()函数调用Tesseract-OCR识别验证码遇到的问题
- Splunk作为日志分析平台与Ossec进行联动
- Android LayoutInflater.from(context).inflate
- 在oracle中where 子句和having子句中的区别
- launch genymotion simulator from command line