typeid() broken for interfaces?

deadalnix deadalnix at gmail.com
Mon Dec 3 15:53:25 PST 2012


On Monday, 3 December 2012 at 21:53:47 UTC, Walter Bright wrote:
> I really don't know what issue you're trying to solve here. The 
> typeid's work fine - and interfaces are not objects. Having the 
> typeid for an interface be an object means you cannot compare 
> typeids of one interface to another interface.
>

You can't instantiate interface. So an underlying type MUST 
exist. The whole point of typeid on expression is to discover 
what is the dynamic type of things, otherwize you'd be using 
typeid(type) not typeid(expression).

> And, my feeling is that if your code needs to implicitly 
> convert interfaces to objects, or even know that an interface 
> instance is implemented by a particular object, your program 
> design is broken and is missing the point of what interfaces 
> are.

The same apply to object in general, and still D does it and for 
good reason (you'll find that few cases where it is actually 
useful and not a design flaw).


More information about the Digitalmars-d mailing list