Style question

Simen Kjaeraas simen.kjaras at gmail.com
Thu Jul 11 12:36:15 PDT 2013


On 2013-07-11, 21:05, Namespace wrote:

>> It seems to me that MyClass has access to MyStaticClass, and thus should
>> also have access to B. If this is the case, why is MyClass using an A
>> instead of a B?
>
> No, they are sadly not part of the same file / module.
> The // ---- should symbolize that. :D

Indeed, yet in MyClass.test1, you do reference MyStaticClass, which is
indicated to be in the same file as B. But no matter.


> Would it be safe if I store A into an uint and cast this to B? Or is  
> that the explicit variant what the compiler do implicit, if I use B b =  
> cast(B) this.a; ?

   uint tmp = A.Foo;
   B result = cast(B)tmp;

gives the exact same result (and hopefully same asm) as casting directly
 from A to B.

That also means that this compiles and gives (un?)expected results:

   uint tmp = 17;
   A a = cast(A)tmp;
   B b = cast(B)a;
   assert(b != B.Foo);
   assert(b != B.Bar);

-- 
Simen


More information about the Digitalmars-d-learn mailing list