Here's an example of the problem I'm having:
package main
import "fmt"
func foo(a int, b ...int) {
fmt.Println(a,b)
}
func main() {
a := 0
aa := 1
b := []int{2,3,4}
foo(a, aa, b...)
}
When I run this I get the error too many arguments in call to foo
. I guess I could understand why this is happening, but what's not clear to me is how I can get around it without having to make a copy of b
with an extra slot at the beginning for aa
(which I'd rather not do, as this code would be running quite often and with b
being somewhat long).
So my question is: Am I just doing this wrong? And if not, what would be the most efficient way to do what I'm trying to do?
(Also, I can't change the signature of foo
).