lists.zerezo.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

***BOGO*** Re: [Mingw-users] GDB and backtrace



Manuel Martín schreef:
> 'Stepping' on gdb I get into a dtor. This is the code:
> 
>    pENu::~pENu()
>    {
>        std::list <lQ*>::iterator iterL;
>        iterL = aLiQu->begin();
>        while ( iterL != aLiQu->end() )
>        {   delete (*iterL);
>            iterL = aLiQu->begin();
>        }
>    }

On a less related side note. That code ^^ will produce an infinite loop.
Which is because you delete the objects pointed to by the pointers from
your container, but you don't advance the iterator to the next pointer
in the container.

You'll need to call the ++ operator on your iterator to advance to the
next element in the container. Thus something like this would loop over
all elements properly (without looping infinitely):

> for (std::list<lQ*>::iterator
>      iterL =  aLiQu->begin();
>      iterL != AliQu->end();
>      ++iterL)
> {
>     delete *iterL;
> }

-- 
Giel

Attachment: signature.asc
Description: OpenPGP digital signature

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users