Navigate from ClassInfo to TypeInfo
Fawzi Mohamed
fmohamed at mac.com
Thu Apr 16 06:12:08 PDT 2009
On 2009-04-16 12:18:31 +0200, davidl <davidl at nospam.org> said:
> 在 Wed, 15 Apr 2009 13:56:20 +0800,Daniel Keep
> <daniel.keep.lists at gmail.com> 写道:
>
>>
>>
>> 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
>
> If the caller only sends the object typeinfo, then the vararg typeinfo
> is so limited to be valid for primitives. It's definitely useless for
> classes cases.
For people interested in runtime introspection tango.core.RuntimeTraits
might be interesting.
Fawzi
More information about the Digitalmars-d
mailing list