get actual classinfo through an interface?

Christopher Wright dhasenan at gmail.com
Thu Nov 22 05:43:19 PST 2007


Ary Borenszweig wrote:
> Christopher Wright wrote:
>> Robert Fraser wrote:
>>> BC wrote:
>>>> new question. since IInterface.classinfo returns IInterface, how to get
>>>> the actual value of the concrete class?
>>>>
>>>
>>> typeid.
>>>
>>> interface Foo { }
>>> class Bar : Foo { }
>>> // ...
>>> Foo foo = new Bar();
>>> TypeInfo ti = typeid(foo);
>>
>> Error: foo is used as a type.
> 
> Probably
> 
> typeid(typeof(foo))

Yes, but then you have:

---
void whatever (IFoo foo) {
    writefln(typeof(foo).stringof);
}

whatever(new Foo()); // prints IFoo
---

typeof is strictly compile-time. BC's looking for a runtime check.


More information about the Digitalmars-d-learn mailing list