Problem with template functions
BCS
BCS at pathlink.com
Thu Jan 11 10:49:31 PST 2007
Olli Aalto wrote:
> Hi!
>
> I've gotten myself into a jam. I've written several templated functions
> which work correctly inside their own modules. I have two modules with
> different kinds of functions, but which couple have the same name ond/or
> alias.
>
> I've written a small example of the problem:
>
> module1.d:
> module module1;
>
> private void _templateFuntion(int T, A...)(int[T][T] arr, A args)
> {
> }
> public alias _templateFuntion!(2, int, int) func;
>
>
> module2.d:
> module module2;
>
> import module1;
>
> private void _templateFuntion(int T, A...)(int[T] arr, A args)
> {
> }
> public alias _templateFuntion!(2, int, int, int) func;
>
> void main()
> {
> int[2][2] array;
> array.func(2, 3);
> }
>
> Compiler output:
> module2.d(14): function
> module2._templateFuntion!(2,int,int,int)._templateFuntion (int[2],(int,
> int, int)) does not match parameter types (int[2][2],int,int)
> module2.d(14): Error: cannot implicitly convert expression (array) of
> type int[2][2] to int[2]
> module2.d(14): Error: expected 4 arguments, not 3
>
> For some reason the compiler doesn't see the template function from
> module1.
>
> Am I doing something wrong or is this something that is just not yet
> supported?
>
> O.
You might try using the fully qualified name "module1._templateFuntion".
If you need to have them truly overload, e.i. using a tuple as the
parameters, I haven't seen that work. I think that it should be doable,
but it isn't. It would open up a a lot of functionality. Something with
mixins would be my choice (like can already be done with functions).
More information about the Digitalmars-d-learn
mailing list