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;
鬼使神差的寫了上面的代碼,發現這樣很容易改變了vector中的第一個元素的值,即使vector的模板參數是const int,不知道是忽略了這個問題,還是有別的目的,希望各位對STL有深入研究的人,指教下,謝謝!
posted on 2007-06-05 18:15
探丫頭 閱讀(1291)
評論(8) 編輯 收藏 引用 所屬分類:
編程語言——C++