instanceof?

Jonathan M Davis jmdavisProg at gmx.com
Wed Aug 1 20:06:09 PDT 2012


On Thursday, August 02, 2012 03:59:01 Maxime Chevalier wrote:
> Getting started with D. I've been doing alot of googling trying
> to find out what's the best way to check if an object is an
> instance of some class. So far, I found you could do:
> 
> if (typeid(obj) == typeid(Class)) doSomething();
> 
> or:
> 
> if (cast(Class)obj) doSomething();
> 
> These both seem a little clumsy, however. Is there a better way
> to do this?

if(cast(Class)obj)

is the canonical way to do it.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list