G
gerg
I'm having to deal with some legacy code which I think may be causeing
some problems. Can STL pro's please add comments about the correctness
of the following code:
class A
{
public:
/// ... assume constructors and such are defined
char* sz; // pointer to memory buffer
};
std::list<A> g_Alist;
/// code snippet in a cleanup routine
std::list<A>::iterator iter=NULL;
for(iter = g_Alist.begin();iter != g_Alist.end(); )
{
// seems to me that erase inside this loop could cause memory
corruption ??
g_Alist.erase(iter++);
// is iter messed up now? even if it is not, is it possible that
// it is redundant?
}
g_Alist.clean();
some problems. Can STL pro's please add comments about the correctness
of the following code:
class A
{
public:
/// ... assume constructors and such are defined
char* sz; // pointer to memory buffer
};
std::list<A> g_Alist;
/// code snippet in a cleanup routine
std::list<A>::iterator iter=NULL;
for(iter = g_Alist.begin();iter != g_Alist.end(); )
{
// seems to me that erase inside this loop could cause memory
corruption ??
g_Alist.erase(iter++);
// is iter messed up now? even if it is not, is it possible that
// it is redundant?
}
g_Alist.clean();