Overriding Private

Christopher Wright dhasenan at gmail.com
Tue May 12 10:04:09 PDT 2009


dsimcha wrote:
> == Quote from Christopher Wright (dhasenan at gmail.com)'s article
>> 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.
> 
> Awesome, but wait a minute, if you can just mixin the contents of another module
> like that, then we don't have a problem.  You can access private members in the
> same module.  Just mix in that module instead of importing it and...you're done.

True. Though you need to be careful about including the 'module' statement.



More information about the Digitalmars-d mailing list