typeid() broken for interfaces?

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Mon Dec 3 02:47:32 PST 2012


Currently typeid(typeid(Interface)) == typeid(ClassInfo). So the interfaces
are using a class's type info, which doesn't make much sense considering
the aforementioned interface logic. If interfaces get their own type info
(like one without a "base" member), it might have an a member called
"objectType", which would be of type ClassInfo and would be null if the
interface is not a class object. then the interface would be perfectly
comparable with other interface types and in case it happens to be a class
object, that could be tested too. And with some more info, the offset of
the interface could be retrieved to compute the object's this reference
(all in case it is indeed a class object).


On Mon, Dec 3, 2012 at 9:58 AM, Walter Bright <newshound2 at digitalmars.com>wrote:

> On 12/3/2012 4:43 PM, Gor Gyolchanyan wrote:
>
>> Wouldn't it be better to return the class's typeinfo if it is a class
>> and the interface's typeinfo if it isn't? The interface would then
>> return the most derived typeinfo that it knows of. I think, just because
>> the interface can be something other then a class object, doesn't mean
>> it should be treated as though it will never be a class object.
>>
>
> A particular interface can be implemented by many different class types,
> or by something that isn't even a class, so returning a typeid that's a
> class typeid would make it impossible to compare one with another.
>
>


-- 
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121203/a40d6266/attachment.html>


More information about the Digitalmars-d mailing list