Need help with variable argument list & template

I am trying to write a simple function which will take an arbitrary number of arguments and return the maximum out of them. It works for individual data types like integers, doubles etc. However, I do not want to write separate function for each data type, so I tried to create a function template, but it does not work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
template<class T>
T findMax(int n,...){
        int i;
        T1 val, maxVal;
        va_list vl;
        va_start(vl, n);
        maxVal=va_arg(vl,T);
        for(i=1;i<n;i++){
                val=va_arg(vl,T);
                maxVal=(val>maxVal)?val:maxVal;
        }
        va_end(vl);
        return maxVal;
}


The error message that I get is:
error: no matching function for call to 'findMax(int, double, double, double)'

Please tell me if I am doing anything wrong, or is there any other way to achieve this ?
Thanks keskiverto.
Will check it.
Topic archived. No new replies allowed.