I would like to do something like this:
container::iterator it = NULL;
switch ( eSomeEnum )
{
case Container1:
it = vecContainer1.begin();
break;
case Container2:
it = vecContainer2.begin();
break;
...
}
for( ; it != itEnd ; ++it )
{
..
}
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.
You just needn't initialize it at all, because iterators are DefaultConstructible.
All you should need to do is change
container::iterator it = NULL;
to
container::iterator it;
and I think your code will work as intended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With