Testing derived type

Koroskin Denis 2korden at gmail.com
Sat Jul 5 14:11:52 PDT 2008


On Sun, 06 Jul 2008 01:03:33 +0400, Nick Sabalausky <a at a.a> wrote:

> I assume there's some way to do the following (D1 and Tango) without
> converting to and comparing strings, but...how?
>
> module modA;
> class base {}
> class derivedA : base {}
> class derivedB : base {}
> class derivedC : base {}
>
> module modB;
> base[] array;
> foreach(base elem; array)
> {
>     if(elem.toString[locatePrior(elem.toString, '.')+1..$] !=
> derivedA.stringof)
>     { /* do stuff */ }
> }
>
>

Maybe this?

...
if ( (cast(derivedA)elem) is null ) {
	/* do stuff */
}
...


More information about the Digitalmars-d-learn mailing list