I am trying to build up a structure using reflect. Most of it is fine, but not when it comes to elements that have pointers.
In my code I would like to have:
switch v.Kind() {
case reflect.Ptr:
val := reflect.New(v.Type().Elem())
v.Set(val)
...
}
which yields
panic: reflect.Value·Set using unaddressable value
v was obtained as follows:
s := &struct{P *int}
v := reflect.ValueOf(s).Elem().Field(0)
so initially v is a nil pointer. What is the correct way, using reflect, to create an new value to assign to a pointer?
Thanks,
-Paul