Overriding Private

Christopher Wright dhasenan at gmail.com
Tue May 12 04:14:43 PDT 2009


dsimcha wrote:
> Is there any hack in D that will allow overriding of privacy settings on
> classes?  For example, I really need a feature that will force D to let me
> mess with the internals of a class that I have no control over from a
> subclass, effectively making private members protected.
> 
> I know this is a bad idea, yada yada yada, but I feel like a language that
> allows manual memory management, casting away immutable, and inline assembler
> should allow some backdoor to cast away private.  Is this anywhere?  If not,
> we should really consider including a cast(public) or something in the spirit
> that, ultimately, the programmer knows what he/she is doing and the language
> should treat the programmer like a consenting adult.

There is one way to do it, but it's ugly:

mixin(Replace!(import("path/to/dfile.d"), "private", "public"));

This requires a compile-time Replace template, which I don't have.



More information about the Digitalmars-d mailing list