#include <iostream>
#include <vector>
using namespace std;
void factorial(vector<int> ivec, typename vector<int>::iterator iter)
{
vector<int>::iterator it;
for (it = iter; it != ivec.end(); it++)
cout << *it << endl;
}
int main()
{
vector<int> ivec;
for (int i = 1; i < 8; i++)
ivec.push_back(i);
factorial(ivec, ivec.begin());
return 0;
}
在视觉工作室2015,它表明,容器作为函数参数
但如果我让ivec
为引用类型(vector<int> & ivec
),它会成功地工作。
为什么?
代码坏,坏,坏,,,所以请你只关注这个问题。