typeid() broken for interfaces?

deadalnix deadalnix at gmail.com
Sun Dec 2 14:17:33 PST 2012


On Saturday, 1 December 2012 at 21:28:05 UTC, Walter Bright wrote:
> On 11/30/2012 9:04 PM, Gor Gyolchanyan wrote:
>> interface I { }
>> class C: I { }
>>
>> I object = new C;
>> assert(typeid(object) == typeid(C)); // fails
>>
>> Is this normal or is it a bug?
>
> Normal, since the typeids of interfaces are not the same as for 
> classes.
>
>> Note, that the same works fine in case of a base class, rather 
>> then an
>> interface.
>
> That works, because classes are classes. Classes are not 
> interfaces.

I'm still waiting to see an object that implement an interface 
but that isn't a class instance.


More information about the Digitalmars-d mailing list