On Sun, Jul 23, 2017 at 12:46 AM, feilengcui008 <feilengcui...@gmail.com> wrote:
> Hi, all:
>     I'm writing a little fuzz tool for struct using reflect package, and
> came across the following case, but didn't find any way to solve it
>
>
> type TestStruct struct {
>     a  *int       // unexported nil ptr field, how to modify it?
>     b  int       // unexported not ptr field, can be modified using
> reflect.NewAt
>     C  *int      // exported nil ptr field,  can be modified using
> reflect.New and value.Set
> }
>
> ts := &TestStruct {}  // a is nil ptr and not exported
> fieldA := reflect.ValueOf(ts).Elem().Field(0)
> // how to modify the value of a using the reflect value fieldA?

In general you can not use reflect to set unexported fields.  If that
were possible, then any package could use reflect to defeat the name
hiding used by any other package, which would make name hiding much
less useful.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to