Alex Rivera | Logout

Go array slice from function return statement

Asked 2011-11-29T22:26:48.753
8

I have the following functions:

func (c *Class)A()[4]byte
func B(x []byte)

I want to call

B(c.A()[:])

but I get this error:

cannot take the address of c.(*Class).A()

How do I properly get a slice of an array returned by a function in Go?

Edit
Report

1 Answer

2

Have you tried sticking the array in a local variable first?

ary := c.A()
B(ary[:])
answered 2011-11-29T22:33:50.010

Your Answer