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

polaris · 2017-10-09 20:00:06 · 605 次点击    
这是一个分享于 2017-10-09 20:00:06 的资源,其中的信息可能已经有所发展或是发生改变。

I wrote a structure like this --> https://imgur.com/IULKNol But there are some deficiencies.

So how can i assignment to variable? Or How do I do this? --> https://imgur.com/L9R4KVX Thanks in advance.


评论:

tiberiousr:

Write NewRuleSet so that it returns a struct that you can attach methods to.

ripeassmango:

your issue is that NewRuleSet does not return a variable

try this

func NewRuleSet() ([]string, []string) {
    return []string{}, []string{}
}

then in your main/test function

func main() {
    depp, conf := NewRuleSet()
}

in Go, like many other languages, you need to explicitly declare what a function returns.

edit:

also, you will need to modify your AddDep and AddConflict to take in the string array as an argument

nagai:
type RuleSet struct {
   depp []string
   conf []string
}
func NewRuleSet() *RuleSet {
   return &RuleSet{[]string{}, []string{}}
}
func (r *RuleSet) IsCoherent() {
   ...
}

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

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