dummy question : runtime type testing...

Lloyd Dupont ld-REMOVE at galador.net
Fri Jun 17 20:28:48 PDT 2011


ho... easy hey!
but how about the other 2 test I'd like be able to run?

bool isTypeOf(T)(TypeInfo ti) {  "return T is ti" }
bool isTypeOf(TypeInfo ti1, TypeInfo ti2) {  "return ti1 is ti2" }



"Jonathan M Davis"  wrote in message 
news:mailman.988.1308367581.14074.digitalmars-d-learn at puremagic.com...

On 2011-06-17 19:58, Lloyd Dupont wrote:
> given
> ----
> A a = ....
> class A {}
> class B : A {}
> ----
> how could I test, at runtime, if "a" is just a "A" or is a "B"?

Cast it. The result will be null if the cast fails.

if(cast(B)a)
    //it's a B
else
    //it's an A but not a B

- Jonathan M Davis 



More information about the Digitalmars-d-learn mailing list