1、const vector <int> vec(10) —— 与const int a[10]是一回事,意思是vec只有10个元素,不能增加了,里面的元素也是不能变化的
1
2
3
4
5
6 |
vector< int > a(10); const
vector< int > b(10); a[1]=10; //正确 b[1]=10; //错误 a.resize(20); //正确 b.resize(20); //错误 |
2、关于vector<const int> ,在GCC下是没有这种用法的,编译不过,不过在VS2005下这样是可以的,不过它好像是把其当作vector<int>来处理的,赋值和resize都是可以的。
const vector<int> 和 vector<const int>问题讨论
原文:http://www.cnblogs.com/yongbufangqi1988/p/3556080.html