use delegate with IUnknown

John C johnch_atms at hotmail.com
Mon Oct 20 05:44:09 PDT 2008


Long Chang Wrote:

> I compile this code got error....
> 
>    1. interface IUnknown{}  
>    2. class klass : IUnknown{   
>    3.     this(){}      
>    4.     void add(void delegate() dg){}  
>    5. }  
>    6. void main(){  
>    7.     auto t  = new klass;      
>    8.     t.add(delegate void(){});     
>    9. }  
> 
> t2.d(8): function t2.klass.add (void delegate()) does not match parameter types (void delegate())
> t2.d(8): Error: cannot implicitly convert expression (__dgliteral1) of type void delegate() to void delegate() 
> 
> 
> this code work fine.
>    1. interface IUnknown_{}  
>    2. class klass : IUnknown_{   
>    3.     this(){}      
>    4.     void add(void delegate() dg){}  
>    5. }  
>    6. void main(){  
>    7.     auto t  = new klass;      
>    8.     t.add(delegate void(){});     
>    9. }  
> 
> 	
> Is this a bug?

No. The compiler treats any interface named IUnknown specially - including modifying the calling convention, so you'll need to add extern(D) on your class.

IUnknown is intended for use with COM anyway.



More information about the Digitalmars-d mailing list