对于如下代码中的printList()函数,为什么括号里已经写const了还要用引用的方式传递呢?
#include<iostream>
#include<list>
using namespace std;
void printList(const list<int>&L)
{
for (list<int>::const_iterator it = L.begin(); it != L.end(); it++)
{
cout << *it << " ";
}
cout << endl;
}
void test01()
{
list<int>L1;
for (int i = 10; i < 51; i+=10)
{
L1.push_back(i);
}
printList(L1);
}
int main()
{
test01();
system("pause");
return 0;
}