How do you check if object o has base type B?
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 4 00:49:09 PST 2016
On Thursday, 4 February 2016 at 05:51:22 UTC, Enjoys Math wrote:
> Consider:
>
> class C {
>
> }
>
> class B : C {
>
> }
>
> class A : B {
>
> }
>
> class D : C {
>
> }
>
> C[] objList;
>
> how do we test if objLis[k] is of base type "B"?
>
> Ie for [new A(), new B(), new D(), new C()] would give output
> [true, true, false, false].
>
> ?
>
> Thank you! :D
if (cast(B)objLis[k])
{
// It's an instance.
}
More information about the Digitalmars-d-learn
mailing list