How do I find the actual types of the elements in a list of classes?

Jack Stouffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 13 15:41:46 PDT 2015


On Thursday, 13 August 2015 at 22:20:35 UTC, Justin Whear wrote:
> foreach (item; parent_list) {
>   if (auto asA = cast(A)item) {
>     asA.method();
>   } else if (auto asB = cast(B)item) {
>     asB.method2();
>   }
> }

On Thursday, 13 August 2015 at 22:20:35 UTC, Justin Whear wrote:

Thanks Justin and rumbu, that makes the code a lot more readable.


More information about the Digitalmars-d-learn mailing list