首页 > 其他 > 详细

const vector<int> 和 vector<const int>问题讨论

时间:2014-02-20 02:25:09      阅读:246      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!