cast(public)

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Fri Jul 17 09:54:33 PDT 2009


dsimcha wrote:

> 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

In general don't believe this is a good idea. Calling private functions and
accessing private variables may violate the class invariant. That's why it
should only be done by member functions, which are bound to maintain that
invariant.

If there was such a back door, a class invariant would mean nothing. Neither
the compiler nor the programmer could ever depend upon it.

However, since D is a systems programming language, which can already cast
away constness and such, it might fit.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list