What should I do for the "s := NewRuleSet ()" structure?

polaris · · 134 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I wrote a structure like this --&gt; <a href="https://imgur.com/IULKNol" rel="nofollow">https://imgur.com/IULKNol</a> But there are some deficiencies. </p> <p>So how can i assignment to variable? Or How do I do this? --&gt; <a href="https://imgur.com/L9R4KVX" rel="nofollow">https://imgur.com/L9R4KVX</a> Thanks in advance.</p> <hr/>**评论:**<br/><br/>tiberiousr: <pre><p>Write NewRuleSet so that it returns a struct that you can attach methods to.</p></pre>ripeassmango: <pre><p>your issue is that NewRuleSet does not return a variable</p> <p>try this</p> <pre><code>func NewRuleSet() ([]string, []string) { return []string{}, []string{} } </code></pre> <p>then in your main/test function</p> <pre><code>func main() { depp, conf := NewRuleSet() } </code></pre> <p>in Go, like many other languages, you need to explicitly declare what a function returns.</p> <p>edit:</p> <p>also, you will need to modify your AddDep and AddConflict to take in the string array as an argument</p></pre>nagai: <pre><pre><code>type RuleSet struct { depp []string conf []string } func NewRuleSet() *RuleSet { return &amp;RuleSet{[]string{}, []string{}} } func (r *RuleSet) IsCoherent() { ... } </code></pre></pre>

入群交流(和以上内容无关):Go中文网 QQ 交流群:729884609 或加微信入微信群:274768166 备注:入群;关注公众号:Go语言中文网

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