Testing derived type

Nick Sabalausky a at a.a
Sat Jul 5 14:07:33 PDT 2008


"Nick Sabalausky" <a at a.a> wrote in message 
news:g4onj4$1cbf$1 at digitalmars.com...
>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 */ }
> }
>

To clarify, what I'm looking for is this):

module modA;
class base {}
class derivedA : base {}
class derivedB : base {}
class derivedC : base {}

module modB;
base[] array;
foreach(base elem; array)
{
    // Do this without converting to and comparing strings
    if(/* elem is not an instance of  'derivedA' */)
    { /* do stuff */ }
}





More information about the Digitalmars-d-learn mailing list