how to compare the type of a subclass
Eric via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 21 14:30:51 PST 2014
On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote:
> On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote:
>>
>> Suppose I have:
>>
>> module test;
>> class X { }
>> class Y : X { }
>>
>> Y y = new Y;
>>
>> X x = y;
>>
>> assert(is(typeof(x) == test.Y); // this assertion will fail
>> assert(typeid(x).toString() == "test.Y"); // this assertion
>> will pass
>>
>> Is there a way I can check the type of x without doing
>> a string comparison?
>>
>> -Eric
>
> assert(typeid(x) == typeid(Y));
Thanks. That works. I have't quite mastered the whole
is/typeof/typeid
thing yet.
More information about the Digitalmars-d-learn
mailing list