Find out most derived class in base class
div0
div0 at sourceforge.net
Fri Nov 19 13:12:40 PST 2010
On 19/11/2010 21:05, Jonathan M Davis wrote:
> On Friday 19 November 2010 12:56:38 Steven Schveighoffer wrote:
>
> And how would you know that at runtime? All reflection in D at this point is
> compile-time reflection, and that isn't going to help you any here (for the very
> reasons that you list). I don't see how you could determine which classes are
> derived from a particular class at runtime. You could use typeof() to determine
> what the exact type of a reference is, but that wouldn't help you determine what
> derived classes exist for a particular type. What you'd really need is runtime
> reflection, which D doesn't have.
>
> - Jonathan M Davis
How would dynamic cast work if you can't find out the inheriting classes
from a reference?
At runtime, the runtime type info for classes forms a DAG.
As D only allows single inheritance it should be trivial to find the
most derived class, though the runtime doesn't currently offer a
function for this.
--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
More information about the Digitalmars-d-learn
mailing list