<p>Hello, </p>
<p>When I run this example code from the book I see the above error : </p>
<pre><code>package main
import "fmt"
func location(name, city string) (name, continent string) {
switch city {
case "New York", "LA", "Chicago":
continent = "North America"
default:
continent = "Unknown"
}
return
}
func main() {
name, continent := location("Matt", "LA")
fmt.Printf("%s lives in %s", name, continent)
}
</code></pre>
<hr/>**评论:**<br/><br/>JJensChr: <pre><p>You can not have a parameter and a named return with the same name in the same function.
That code worked in Go 1.0, but not since. It was a bug that it even worked in the first place.</p>
<p><a href="https://code.google.com/p/go-wiki/wiki/Go1point1Gotchas" rel="nofollow">https://code.google.com/p/go-wiki/wiki/Go1point1Gotchas</a></p>
<p>If you follow the link below the example ( <a href="http://play.golang.org/p/aOSABxXoiU" rel="nofollow">http://play.golang.org/p/aOSABxXoiU</a> ) there is a better example that works.</p></pre>netzdamon: <pre><p>in func location(name, city string) (name, continent string) you are using the variable name twice. Change the second name to n or something. Then it should compile.</p></pre>Paulo60: <pre><p>func location(name string, city string) (string, string) {</p>
<p>}</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传