On 1/19/13 9:23 AM, Maxim Fomin wrote:
On Saturday, 19 January 2013 at 13:57:02 UTC, Andrei Alexandrescu wrote:
On 1/19/13 8:21 AM, Maxim Fomin wrote:
How much chances does this program have?
Looks like an ODR violation, but oddly there's nothing stopping us
from making this work. It's a good idea to pursue.
Andrei
Unfortunately, this will never work in general. That code runs because
private member was placed after public and because _d_new_class got
"right" Typeinfo (compiled from mylib, not from main). If a private
member is placed before a public one, than this will lead to troubles
because dmd just generates (wrong) offsets from base pointer.
What I wanted to say is that in D private members should be included in
declaration in general case (sometimes the opposite may work by chance)
which partly defeats encapsulation.
For example, if you make changes in class which affects order of private
members, you have to recompile all code which uses that class. That is a
poor encapsulation.
I knew where you were driving. These are well-known tradeoffs. More
robust modularity could be achieved at the expense of good layout. I was
saying it would be interesting if we could allow better hiding in select
cases (like the one in the example).
Andrei