dummy question : runtime type testing...

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 17 20:26:09 PDT 2011


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