Variadic Functions in C++
Within the function, the type of nums
is equivalent to std::vector<int>
. We can call nums.size()
, iterate over it with a range-based for loop, etc.
Variadic functions can be called in the usual way with individual arguments.
If you already have multiple args in a slice, apply them to a variadic function using a braced-init-list like this.
To run the program, put the code in a file named variadic_functions.cpp
and use the following commands to compile and run it:
Another key aspect of functions in C++ is their ability to form closures, which we’ll look at next.