vector<const int> cVec;
cVec.push_back(10);
cVec.push_back(20);
int& firstVal = cVec.front();
cout<<"The first element is :"<<firstVal<<endl;
firstVal++;
firstVal = cVec.front();
cout<<"The first element is :"<<firstVal<<endl;
鬼使神差的寫了上面的代碼,發(fā)現(xiàn)這樣很容易改變了vector中的第一個(gè)元素的值,即使vector的模板參數(shù)是const int,不知道是忽略了這個(gè)問題,還是有別的目的,希望各位對STL有深入研究的人,指教下,謝謝!