Possible Bug with Interfaces in Variadic Functions?

Daniel Giddings danielg at microforte.com.au
Tue Sep 26 16:28:03 PDT 2006


That works nicely.

Thanks,

:-) Dan

Bruno Medeiros wrote:
> You are using typeid() comparison incorrectly (no fault of yours, the 
> spec is erroneous, see http://d.puremagic.com/issues/show_bug.cgi?id=373 ).
> 
> Using '==' to compare TypeInfos will test the equality of the type's 
> "archetype", that is, if they are both a struct, a pointer, a class, 
> etc. Apparently interfaces and classes belong to the same archetype 
> (which is class), so any TypeInfo equality comparison between any of 
> these will allways result true.
> Using 'is' to compare TypeInfos will test for an exact type match, which 
> is also not what you, since it will disregard polymorphism.
> 
> Here's how you can do it:
> 
>   // Check for class archetype:
>   if( _arguments[i] == typeid(Object) ) {
>     auto obj = va_arg!(Object)(_argptr);
>     // check if obj is-a I
>     if( (cast(I) obj) != null ) {
>       I myi = cast(I) obj;
>       // use myi
>       writefln(myi.f());
>     }
>   }
> 



More information about the Digitalmars-d-learn mailing list