Newbie initial comments on D language - scope
Walter Bright
newshound1 at digitalmars.com
Sat Feb 2 14:12:44 PST 2008
Edward Diener wrote:
> In your above, if the c object is 'scope', whether it is because the C
> class is 'scope' or, as in your example, you specify 'scope' on the
> object ( which in current D is the same thing as saying that the C class
> is 'scope' ) then the assignment to another object makes that object
> 'scope' automatically. This is yet another reason why 'scope' at the
> compiler should be tracked at the object level, not at the class level.
> The canonical situation is:
>
> class C { ... }
> scope class D : C { ... }
>
> scope ( redundant IMO ) D d = new D(...);
> C c = d;
>
> Clearly c, whose polymorphical type is a D, has to be 'scope'.
Let's look at it by analogy to 'const'. Implicitly converting a const D
to its base class will produce a const C, not a C. A const C cannot be
assigned to a C.
I think it should work similarly with scope, and that like const, it
should be part of the type system (a proxy struct would accomplish
that). Making it a dynamic part of the object would exact a heavy cost
for most objects which don't need it.
More information about the Digitalmars-d
mailing list