typeid() broken for interfaces?

Walter Bright newshound2 at digitalmars.com
Mon Dec 3 13:53:44 PST 2012


On 12/4/2012 8:07 AM, deadalnix wrote:
> On Monday, 3 December 2012 at 20:59:24 UTC, Walter Bright wrote:
>> On 12/4/2012 2:52 AM, Jacob Carlborg wrote:
>>> Note, I'm not saying that an interface should be implicitly converted to
>>> any class, only to Object.
>>
>>
>> But not all interfaces come from Objects.
>
> So I thought about all that.
>
> typeid is about runtime type detection. As all interfaces are not coming
> from object, it is definitively an issue to resolve them as object
> sometime. However, keeping tied to the static type when runtime typeid
> is asked for is a but sad.
>
> But interfaces that don't resolve as object are well know at compile
> time.
> So isn't it possible to resolve all interfaces that we know are
> objects into object's typeid ? After all, this is what typeid is about.

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.

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.


More information about the Digitalmars-d mailing list