dynamic type casting in D

Michal Minich michal.minich at gmail.com
Sun May 30 14:27:42 PDT 2010


On Sun, 30 May 2010 19:40:27 +0000, dave wrote:

> if(implements(typeof(something).classinfo, A.classinfo))

in simpler way:

In order to determine if an object o is an instance of a class B use a 
cast:

if (cast(B) o)
{
    // o is an instance of B
}
else
{
    // o is not an instance of B
}

or you can also create variable of type B inline:

if (auto b = cast(B) o) { use b ... } 

you can find more type information using 'is' expression
http://www.digitalmars.com/d/1.0/expression.html#IsExpression


More information about the Digitalmars-d-learn mailing list