iterator pointing to invalid container



 DEVELOP > c-Plus-Plus > iterator pointing to invalid container

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Parapura Rajkumar"
Date: 03 Jan 2007 10:33:34 PM
Object: iterator pointing to invalid container
int main(int argc, char* argv[])
{
std::map<int, int>::iterator footest;
{
std::map<int, int> foo;
foo[0] = 0;
footest = foo.begin();
}
return 0;
}
Is this undefined behavior? Please note that footest is going out of
scope before std::map. In theory an implementation could have a
iterator destructor that could still access the std::map ?
Thanks
Raj
.

User: "Victor Bazarov"

Title: Re: iterator pointing to invalid container 03 Jan 2007 11:47:13 PM
Parapura Rajkumar wrote:

int main(int argc, char* argv[])
{
std::map<int, int>::iterator footest;
{
std::map<int, int> foo;
foo[0] = 0;
footest = foo.begin();
}
return 0;
}

Is this undefined behavior? Please note that footest is going out of
scope before std::map.

You mean, "after 'foo'", don't you?

In theory an implementation could have a
iterator destructor that could still access the std::map ?

No. The iterator is allowed to be invalid, that does not affect
its destruction.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
User: "Roland Pibinger"

Title: Re: iterator pointing to invalid container 04 Jan 2007 07:11:15 AM
On Thu, 4 Jan 2007 00:47:13 -0500, "Victor Bazarov" wrote:

Parapura Rajkumar wrote:

int main(int argc, char* argv[])
{
std::map<int, int>::iterator footest;
{
std::map<int, int> foo;
foo[0] = 0;
footest = foo.begin();
}
return 0;
}

Is this undefined behavior? Please note that footest is going out of
scope before std::map.


You mean, "after 'foo'", don't you?

In theory an implementation could have a
iterator destructor that could still access the std::map ?


No. The iterator is allowed to be invalid, that does not affect
its destruction.

Different kinds of invalid iterators are described here:
http://www.angelikalanger.com/Conferences/Slides/CppInvalidIterators-DevConnections-2002.pdf
Best wishes,
Roland Pibinger
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER