/** Compute the sum of elements of a vector */
template <unsigned int N>
class Series
{
typedef int Vector[10];
public:
static double Compute(Vector & vector)
{
return vector[N-1] + Series<N-1>::Compute( vector ); // recursion
}
private:
};
double Series<1>::Compute(Vector & vector) // Specialization for terminating the recursion
{
return vector[0];
}
int main()
{
double sum;
int values[10];
sum = Series<10>::Compute(values);
return 0;
}