Navigate from ClassInfo to TypeInfo
davidl
davidl at nospam.org
Thu Apr 16 03:18:31 PDT 2009
在 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.
--
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list