bootcamp book, chapter 1: ./test.go:5: duplicate argument name

xuanbao · · 1160 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello, </p> <p>When I run this example code from the book I see the above error : </p> <pre><code>package main import &#34;fmt&#34; func location(name, city string) (name, continent string) { switch city { case &#34;New York&#34;, &#34;LA&#34;, &#34;Chicago&#34;: continent = &#34;North America&#34; default: continent = &#34;Unknown&#34; } return } func main() { name, continent := location(&#34;Matt&#34;, &#34;LA&#34;) fmt.Printf(&#34;%s lives in %s&#34;, 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

1160 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传