How to check if the iterator is initialized?

前端 未结 11 1337
孤城傲影
孤城傲影 2021-02-05 06:30

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
         


        
11条回答
  •  北海茫月
    2021-02-05 07:22

    I used the following solution:

    const MyList_t::const_iterator NullIterator(NULL);
    const_iterator MyList_t::MyIterator;
    

    Then a check is possible:

    if (NullIterator != MyIterator) {}
    

提交回复
热议问题