Navigate from ClassInfo to TypeInfo

Frank Benoit keinfarbton at googlemail.com
Tue Apr 14 23:23:46 PDT 2009


Daniel Keep schrieb:
> 
> davidl wrote:
>> 在 Wed, 15 Apr 2009 10:14:42 +0800,Jarrett Billingsley
>> <jarrett.billingsley at gmail.com> 写道:
>>
>>> 2009/4/14 davidl <davidl at nospam.org>:
>>>> Send this object to vararg func, and retrieve the TypeInfo there and
>>>> return?
>>> No.  The typeinfo passed to vararg functions is also determined at
>>> compile-time.
>> so it's a bug?
>>
>> I think vararg funcs always want the real typeinfo of the object
> 
> No, they get the typeinfo of what they're passed.
> 
>> class A {}
>> class B : A {}
>>
>> void foo(...) {}
>>
>> void bar(A a) { foo(a); }
>>
>> void main()
>> {
>>     scope b = new B;
>>     bar(b);
>> }
> 
> bar cannot possibly know what the "real" TypeInfo of a is.  But that
> doesn't matter because it's passing an A with A's TypeInfo.  And if foo
> is maybe interested in Bs, then it can just try to up-cast.
> 
>   -- Daniel

Or it can request the classinfo of the passed object. Hey, and now the
typeinfo please :)



More information about the Digitalmars-d mailing list