复制代码 代码如下:
#include <iostream>
#include <initializer_list>
using namespace std;
int get_sum(int, initializer_list<int>);
int main(int argc, char *argv[])
{
cout << get_sum(2, {1,2,3}) << endl;
return 0;
}
int get_sum(int i, initializer_list<int> il) {
int sum = 0;
sum += i;
for (auto a : il) {
sum += a;
}
return sum;
}