Run-time reflection for class inheritance

Michael Green abc.mikey at
Mon Dec 2 17:50:49 UTC 2019

On Sunday, 1 December 2019 at 14:42:46 UTC, Adam D. Ruppe wrote:
> You can get the type at runtime by simply casting it...
> if(auto c = cast(EventSocket) event) {
>    // is an event socket
> }


I guess you need to be careful about which order you do those 
tests so as not to cast to more general types before testing for 
specific ones.

I also came up with

     if (typeid(event) == typeid(EventTimer)) {
         // do something

The reason I was leaning toward the first one is that it could be 
put in a switch as it's just string compares.

I guess having it cast as part of the check is useful.

More information about the Digitalmars-d-learn mailing list