I thought this is a simple thing to do, but I was wrong. I can't pass integer
as pointer to function using interface{}
.
Example:
var test int
someChange(&test)
fmt.Printf("after function: %d", test)
func someChange(i interface{}) error{
newFunnyValue := 42
i = newFunnyValue
fmt.Printf("hello from someChange now value test is: %d" , i)
return nil //change gone ok, so nil
}
And result:
hello from someChange now value test is: 42
after function: 0
I read that interface{}
is similar to void*
so above code should work but it's not, why? I want to add that if I pass some object which is a struct, everything works good.
Do I have to wrap int
in some struct?
Edit: