#include<iostream>
#include<string>
using namespace std;
int add(initializer_list<int> ls)
{
int result{0};
for (auto beg = begin(ls); beg != end(ls); beg++)
{
result += *beg;
}
return result;
}
void errmsg(initializer_list<string> ls)
{
string str;
for (auto const &m : ls)
{
str += m;
str += " ";
}
cout << str << endl;
}
int main()
{
cout << add({ 5,6,7 ,8,9,9}) << endl;
errmsg({ "helle","jef","kitty" });
}
范围for内声明成引用可以省一次复制,string复制消耗可能是比较大的