how to get a pointer of element's value in a double-linked list (go-lang) -
i want modify element's value in double-linked list, don't know how pointer, because element's value nil interface defined go-lang itself. far know is, must type assertion before element's value like:
val, ok := ele.value.(type) if ok { // something... }
but if modify val
useless. hint?
thanks.
there 2 pretty straight forward options. they're going involve type asserting because you're using interface{}
you can store pointer , type assert:
var q interface{} var int q = &i *(q.(*int)) = 5
you can reassign it:
var q interface{} q = 5 b := q.(int) q = 2*b
i think reassigning makes sense. if you're doing in function need return new value. i'm sure there other ways change around, think simple best.
of course in real work checking nice.
Comments
Post a Comment