Notes on Defective C++

Sean Kelly sean at
Sun Dec 7 18:27:13 PST 2008

Nick Sabalausky wrote:
> "Walter Bright" <newshound1 at> wrote in message 
> news:ghh7r5$436$1 at
>> bearophile wrote:
>>> 1) No compile time encapsulation: "In naturally written C++ code,
>>> changing the private members of a class requires recompilation of the
>>> code using the class." I think D solves this problem, you only have
>>> to compile the module the contains the class (generally a module
>>> contains related classes/functions).
>> D doesn't solve this problem. Changing the private members changes offsets 
>> of other members and derived classes, so they must all be recompiled. 
>> Inline functions are also, of course, affected.
>> The way to avoid this is to use interfaces.
> Would there be any problem with making all the public members come first, 
> then the protected, then the private? That way changing private members 
> wouldn't change the offsets of public and protected members. (Not that I 
> consider this a major issue.) 

With inheritance, I'm not sure this is possible.

class A
   public int a;
   private int b;

class B : A
   public int c;
   private int d;


More information about the Digitalmars-d mailing list