cpp header organizer
Matt Rogers
mattr at kde.org
Thu Jan 13 15:58:12 UTC 2005
On Thursday 13 January 2005 08:34 am, Felix Berger wrote:
> On Tuesday 11 January 2005 13:40, Roberto Raggi wrote:
> > tnx a lot Felix, I will take a look at it later at home
>
> Hi Roberto,
>
> I found the culprit, it's in my code:
>
> for (QPtrListIterator<BaseSpecifierAST> i(base->baseSpecifierList());
> i.current(); ++i) {
> parseBaseSpecifier(i.current());
> }
>
> The problem is, that QPtrlist is copied when returned from
> base->baseSpecifierList, this is a "deep" copy in the sense that all item
> references are copied and there is no connection to the original list. But
> since I didn't assign the list to stack variable, it goes out of scope
> immediately, thus invalidating all its iterators.
>
> A working implementation would have to look like this:
>
> QPtrList<BaseSpecifierAST> list(base->baseSpecifierList());
> for (QPtrListIterator<BaseSpecifierAST> i(list);
> i.current(); ++i) {
> parseBaseSpecifier(i.current());
> }
>
> That was a bit tricky, I suppose a QValueList<BaseSpecifierAST*> would
> yield a more intuitive behaviour since all instances reference the same
> internal list when copied. Don't know about autodeleting the items though.
>
QValueList would behave the same way wrt to the iterators becoming invalid
after the list goes out of scope IIRC
More information about the KDevelop-devel
mailing list