Function overloading concern

Carlos Santander csantander619 at gmail.com
Thu Mar 9 16:20:03 PST 2006


Sean Kelly escribió:
> 
> By the way, the more complex C++ examples don't work in D anyway, 
> because D is module-based.  For example, it's more likely func would be 
> defined in a third module like so:
> 
> Module C:
> 
>     module c;
>     import b; // let's say b is the default implementation
> 
>     template func( T )
>     {
>         void func( inout T t1, inout T t2 )
>         {
>             swap( t1, t2 );
>         }
>     }
> 
> Main:
> 
>     import a;
>     import c;
> 
>     void main()
>     {
>         int i = 1, j = 2;
>         func( s, t );
>     }
> 
> However, this doesn't work in D even without overloading.  So perhaps 
> it's not much of an issue here anyway.
> 
> 
> Sean

This one, I don't understand. I don't have DMD to try the code, but I think the 
call sequence would be something like:

main -> c.func -> b.swap

The main module imports a, but it's never used.

The only thing that I can think of is that you want c.func to use a.swap because 
it was imported in main, but it doesn't make much sense (for me, anyway) because 
c never knew about a. I don't know if C++ allows that, but I would say it's not 
a very good design. There should be another way. IMHO.

-- 
Carlos Santander Bernal



More information about the Digitalmars-d mailing list