I list the code from the book "Programming in Go". I test it but it didn't work well.
error: "not enough arguments in call to BitFlag.String"
Goplayground Code: http://play.golang.org/p/FG23LdS_xK
type BitFlag int
func main() {
flag := Active | Send
BitFlag.String();
}
func (flag BitFlag) String() string {
...
}
Why do I see this error message?
You need to call String on an instance of BitFlag
(here 'flag
'), not on the BitFlag
type itself.
flag := Active | Send
fmt.Println(strconv.Itoa(int(flag)))
fmt.Println(flag.String())
See this play.golang.org example.
Output:
3
3(Active|Send)