1

please comment the code what is wrong in my implementation of this known task

template <typename T>
T arithmetic_sum(T first) {
    return first;
}

template<typename T, typename... Types>
auto arithmetic_sum(T first, Types ...others) ->decltype(first + arithmetic_sum(others...)) {
    return first + arithmetic_sum(others...);
}

(GCC 4.9)

e.g. this call

auto i = arithmetic_sum(123, 123.45, 0.55l);

can't be compiled with error:

error: no matching function for call to 'arithmetic_sum(int, double, long double)'

auto i = arithmetic_sum(123, 123.45, 0.55l); ^

amigo421
  • 2,429
  • 4
  • 26
  • 55

0 Answers0