本文介绍了如何检查迭代器是否初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我为一个迭代器使用默认构造函数,如何检查它是否以后分配?

If I use a default constructor for an iterator, how to check if it was assigned later on?

对于指针,我可以这样做:

For pointers, I could do this :

int *p = NULL;
/// some code
if ( NULL == p ) {
  // do stuff
}

如何对迭代器执行上面的操作?
是否有可能?

How do I do the above for iterators?Is it possible at all?

#include <iostream>
#include <list>

int main ()
{
    std::list<int>::iterator it;

  if ( NULL == it ) // this fails
  {
      std::cout<<"do stuff" << std::endl;
  }
}


推荐答案

I设法在当前标准(c ++ 03)中找到这个。 24.1 p 5告诉:

I managed to find this in the current standard (c++03 ). 24.1 p 5 tells :

(强调我的)

所以答案是:不,不可能。

So the answer is : no, it is not possible.

这篇关于如何检查迭代器是否初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 11:22
查看更多