typeid() broken for interfaces?

Maxim Fomin maxim at maxim-fomin.ru
Fri Nov 30 02:55:46 PST 2012


On Friday, 30 November 2012 at 10:05:21 UTC, 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?
> Note, that the same works fine in case of a base class, rather 
> then an
> interface.

It works according to spec. Object is expression of type 
interface I, so no dynamic type search is performed.


More information about the Digitalmars-d mailing list