If you are familiar with c++11, there is a new concept introduced called variadic templates; which in essence allows one to create functions like you have mentioned which can take a varied amount of arguements.
The syntax for declaring such function looks like:
template <typename ... Types>
void someFunc(Types ...args) {}
Another option is to use an std::initializer_list along with std::accumulate to achieve this since you already know the types of the variables you will be using. An example using your program is this:
#include <iostream>
#include <initializer_list>
#include <numeric>
using namespace std;
double sum( initializer_list<double> vals ) {
return accumulate(vals.begin(), vals.end(), 0.0);
}
int main() {
// your code goes here
cout << sum({2, 3, 4.6, 5, 6, 74.322, 1}) << endl;
return 0;
}