cast(public)

downs default_357-line at yahoo.de
Fri Jul 17 13:53:00 PDT 2009


dsimcha wrote:
> I know I've probably mentioned this one here before, but it was buried in long
> threads.
> 
> Could we put a feature in the language that allows private member variables to
> be cast to public?  The idea is that, if a class/struct designer makes
> something private, they're saying it's a bad idea to mess with it, and that
> you do so at your own risk.  However, I think there needs to be a back door to
> cowboy this one, because otherwise private/protected is just too restrictive
> for a language like D.  It would work something like this:
> 
> struct Foo {
>     private uint bar;
> }
> 
> void main() {
>     Foo foo;
>     foo.bar++;  // error
>     (cast(public) foo.bar)++;  // Works.
> }

I can second this.

For instance, in Phobos1 there is no way to create a Socket from a file handle, so I have to monkey with offsets in my IRC bot code.



More information about the Digitalmars-d mailing list