I am trying to make a template function that has a array as parameter. The function retruns sum of the numbers in the array.
This is my code:
template <class var>
var sum_numbers(var array[]) {
var sum = 0;
for (int f1=0; array[f1]!='\0'; f1++) {
sum = sum + array[f1];
}
return sum;
}
The function always returns
-2001120059
Can you please give some idea how to improve my code, and can you please give me some reference where to find more information about templates?
Thank you very much.
UPDATE: My input, and function call:
int a[] = {1,2,3,4,5};
cout << sum_numbers(a) << endl;