Last active
May 7, 2016 18:45
-
-
Save shakram02/8055682f645c2c6eef02ffe1c295ee77 to your computer and use it in GitHub Desktop.
Sums all the input arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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