Is there other way to do that?

mw mingwu at gmail.com
Mon Feb 15 15:17:32 UTC 2021


On Monday, 15 February 2021 at 07:26:56 UTC, Jack wrote:
> I need to check if an instance is of a specific type derived 
> from my base class but this class has template parameter and 
> this type isn't available at time I'm checking it. Something 
> like:
>
> class B { }
> class A(T) : B { }
> class X : B { }
> class Z : B { }
>
> auto c = can be any derived class from B
> bool isX = cast(A!???) c !is null;
> assert(isX);
>

You have object instance, why not just use virtual function?


https://forum.dlang.org/post/gemozfonxoohojtlbqgj@forum.dlang.org

Cast always smells hacking.


More information about the Digitalmars-d-learn mailing list