fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. auto sum() { return {}; }
  5.  
  6. template<typename Head, typename... Tail>
  7. auto sum(Head head, Tail... tail)
  8. {
  9. return head+sum(tail...);
  10. }
  11.  
  12. int main() {
  13. cout<< sum(1,2.4) << endl;
  14. cout<< sum("hello ", "world") << endl;
  15. return 0;
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:21: error: cannot deduce return type from initializer list
auto sum() { return {}; }
                    ^~
prog.cpp:9:17: error: no matching function for call to 'sum'
    return head+sum(tail...);
                ^~~
prog.cpp:9:17: note: in instantiation of function template specialization 'sum<double>' requested here
prog.cpp:13:12: note: in instantiation of function template specialization 'sum<int, double>' requested here
    cout<< sum(1,2.4) << endl;
           ^
prog.cpp:7:6: note: candidate function template not viable: requires at least argument 'head', but no arguments were provided
auto sum(Head head, Tail... tail)
     ^
prog.cpp:9:17: error: no matching function for call to 'sum'
    return head+sum(tail...);
                ^~~
prog.cpp:9:17: note: in instantiation of function template specialization 'sum<const char *>' requested here
prog.cpp:14:12: note: in instantiation of function template specialization 'sum<const char *, const char *>' requested here
    cout<< sum("hello ", "world") << endl;
           ^
prog.cpp:7:6: note: candidate function template not viable: requires at least argument 'head', but no arguments were provided
auto sum(Head head, Tail... tail)
     ^
3 errors generated.
stdout
Standard output is empty