John Simon wrote:
Sean Kelly Wrote:

Oh, I should mention that I'm not sure how the compiler would handle this scenario:

class A { byte[16]; }
class B { byte[32]; }
class C {
     this( bool b ) {
         if( b ) o = new A;
         else    o = new B;
     }
     scope Object o;
}

If I had to guess I'd say that the compiler would either reserve the max size necessary to store both A or B, or that in non-trivial cases it just wouldn't bother with reserving space for o at all.

Wrong. The Object is constructed when it comes into scope, and destructed when 
it leaves scope. Classes can't have an 'opAssign', instead the reference is 
reassigned. Since the reference is invariant/immutable here, this throws a 
compile time error.

I'm talking about a proposed new feature, not an existing one. Please take this example in context.

Reply via email to