grep

torhu no at spam.invalid
Fri May 9 23:31:42 PDT 2008


janderson wrote:
> I guess your not being serious but in case you are, you want to make bad 
> coding difficult to do and good coding easy.  People area not likely to 
> go to that much effort to circumvent cast.  There are a couple of other 
> ways to get around cast:
> 
> //ie
> class A
> {
> 
> };
> 
> class B : A
> {
> 
> };
> 
> 	B[] b;
> 	b ~= new B;
> 	A[] a = b;
> 	a ~= new A;
> //b[1] Is not an A type (not a B type), but is essentially a reinterpret 
> A -> B.
> 

But array b has no element at index 1, it's length is still 1.

This gets the desired effect:

  	B[] b;
  	b ~= new B;
  	b ~= new B;
  	A[] a = b[0..1];
  	a ~= new A;

Now, the second element of b will be an A.  On the other hand, appending 
to slices could easily be considered bad style.



More information about the Digitalmars-d mailing list