typeof on protected field

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Jun 16 18:15:07 UTC 2018


On Saturday, June 16, 2018 13:12:13 bauss via Digitalmars-d-learn wrote:
> On Saturday, 16 June 2018 at 08:32:38 UTC, DigitalDesigns wrote:
> > mixin(`foo!(typeof(T.`~m~`));
> >
> > gives me an error about m being protected.
> >
> > Error: class `X` member `name` is not accessible.
> >
> > this also happens when using __traits(getMember, T, m); X is in
> > another module. Works fine when X is in the same module.
> >
> > I need to get the protected and private members for
> > serialization.
>
> You can't get that information when they're in another module,
> unfortunately.
>
> The only solution would be to expose them as public or have a
> public member expose them.

There has been discussion of making private, protected, etc. accessible to
type introspection, and I expect that it will work at some point, but yeah,
at the moment, it doesn't work.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list