Focus

Maxim Fomin maxim at maxim-fomin.ru
Sat Jan 19 06:23:36 PST 2013


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.


More information about the Digitalmars-d mailing list