Initializer list vs. vector
问题 In C++11, one can use initializer lists to initialize parameters in functions. What is the purpose of it? Can't the same be done with const vectors? What is the difference of the two programs below? Using an initializer list: #include <iostream> using namespace std; int sumL(initializer_list<int> l){ int sum = 0; for (const auto i: l){ sum += i; } return sum; } int main(){ cout << sumL({1, 2, 3}) << "\n"; return 0; } Using a const vector: #include <iostream> #include <vector> using namespace