让人头痛的Vector(提问篇)
2004-08-07 16:55 FantasySoft 阅读(12597) 评论(16) 编辑 收藏 举报 在写完了此Vector非彼Vector这篇随笔之后,带着留下来的一个问题——Java中的Vector与STL中Vector的区别,我开始集中精力去了解STL中的Vector了。原本以为,有大名鼎鼎的好书《C++ Standard Library, The: A Tutorial and Reference》坐镇,进度应该会很挺快的,结果是被一个小问题绊倒,摔得满天星星,到现在还头痛呢。
大家可以先看这段代码(在VC++6.0上编译执行):
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
先问大家一个问题,"The vector is empty!"会被打印出来吗?如果将注释中的1、2两行改为:
vec.push_back(0);
vec.push_back(1);
vec.push_back(1);
你的答案又会是什么呢?
答案请看:让人头痛的Vector(思索篇)