Need some help with struct variable assignment in functions

polaris · · 436 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m still learning the syntax candy and I need a class-like object, so I&#39;ve turned to structs. I&#39;m not sure why the code in my example below isn&#39;t assigning a value I&#39;m attempting. Can anyone give me some insight about how to proceed with this? </p> <p><a href="https://play.golang.org/p/E74NBnDWuU" rel="nofollow">https://play.golang.org/p/E74NBnDWuU</a></p> <hr/>**评论:**<br/><br/>fr4nk3n: <pre><p>You have to use a pointer to the struct. <a href="https://play.golang.org/p/oTUkjV1UTP" rel="nofollow">https://play.golang.org/p/oTUkjV1UTP</a></p></pre>Marvelt: <pre><p>You need to pass the receiver as a pointer in order to update it.</p> <p><a href="https://play.golang.org/p/etJKmvp5H8" rel="nofollow">https://play.golang.org/p/etJKmvp5H8</a></p></pre>igknighted: <pre><p>Thanks. This has been kicking my arse for a half hour now. </p></pre>fortyninezeronine: <pre><p>This link should tell you everything you need to know: <a href="https://golang.org/doc/effective_go.html#methods" rel="nofollow">https://golang.org/doc/effective_go.html#methods</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

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