简体   繁体   中英

Error while creating slice of bool type in Golang?

I am trying to create slice of type bool but receiving error "cannot make type bool"

isVisited := make(bool,5,5)

./jdoodle.go:10:19: cannot make type bool

I also checked slice doc https://blog.golang.org/slices-intro

And several other articles on Golang but no success.

Thanks for help in advance.

You are missing [] . To make isVisited a slice you need to do isVisited:= make([]bool, 5, 5) .

[]bool denotes a slice of type bool .

There's a nice example in Effective Go both in section about make() and slices .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM