/****************************/ /* 関数(可変長引数) */ /* coded by Y.Suganuma */ /****************************/ #include <iostream> #include <vector> #include <string> using namespace std; template <class cl> cl t_plus(cl init, vector<cl> x) { cl sum = init; for (auto s : x) sum += s; return sum; } int main() { vector<string> x = {"abc", "def", "ghi"}; string str = t_plus(string(), x); cout << "結合結果 : " << str << endl; vector<int> y = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum = t_plus(0, y); cout << "合計 : " << sum << endl; return 0; }