使用STL迭代器而不初始化它 [英] Using an STL Iterator without initialising it

查看:186
本文介绍了使用STL迭代器而不初始化它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

container::iterator it = NULL;

switch ( eSomeEnum )
{
case Container1:
it = vecContainer1.begin();
break;

case Container2:
it = vecContainer2.begin();
break;
...


}

for( ; it != itEnd ; ++it )
{ 
..
}

但是我无法创建迭代器并将其初始化为NULL。有什么方法可以做到这一点吗?理想情况下,我只是在交换机中创建并分配迭代器,但它会立即超出范围。

But I can't create and initialise an iterator to NULL. Is there some way I can do this? Ideally I would just create and assign the iterator in the switch, but then it would go out of scope immediately.

推荐答案

你只是根本不需要初始化它,因为迭代器是DefaultConstructible。

You just needn't initialize it at all, because iterators are DefaultConstructible.

这篇关于使用STL迭代器而不初始化它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆