Skip to content

Instantly share code, notes, and snippets.

@shakram02
Last active May 7, 2016 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakram02/8055682f645c2c6eef02ffe1c295ee77 to your computer and use it in GitHub Desktop.
Save shakram02/8055682f645c2c6eef02ffe1c295ee77 to your computer and use it in GitHub Desktop.
Sums all the input arguments
#include <iostream>
#include<stdlib.h>
template <typename T>
int Sum(T t)
{
return t;
}
template<typename T, typename... Args>
int Sum(T t, Args... args) // recursive variadic function
{
return t + Sum(args...);
}
int main()
{
int result = Sum(1,2,3,4);
std:: cout<< result << std::endl;
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment