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:
ripeassmango:Write NewRuleSet so that it returns a struct that you can attach methods to.
nagai: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
type RuleSet struct { depp []string conf []string } func NewRuleSet() *RuleSet { return &RuleSet{[]string{}, []string{}} } func (r *RuleSet) IsCoherent() { ... }
