how to compare the type of a subclass
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 21 15:14:24 PST 2014
On Friday, 21 November 2014 at 22:30:52 UTC, Eric wrote:
> On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote:
>> On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote:
[...]
>>> class X { }
>>> class Y : X { }
>>>
>>> Y y = new Y;
>>>
>>> X x = y;
[...]
> I have't quite mastered the whole is/typeof/typeid
> thing yet.
Maybe this helps:
There are two worlds:
* the static world = the compile time world = the world of types
and constant values,
* the dynamic = the run time world = the world of values.
Obviously, there are no variable values in the static world.
Maybe less obviously, there are no types in the dynamic world.
The variable x is statically typed as X. is(...) and typeof(...)
operate on this level. But the object stored in x is being
constructed as a Y at run time. That information is available
through typeid.
typeid(...) is not a type, it's a value of type TypeInfo which
corresponds to a type. typeid(Y) and typeid(x) are TypeInfo
objects both corresponding to the type Y.
More information about the Digitalmars-d-learn
mailing list