cpp header organizer

Felix Berger bflat1 at gmx.net
Thu Jan 13 15:48:16 UTC 2005


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.

Thanks for helping out.

Sincerely,
Felix Berger

-- 
Use Debian GNU/Linux!
http://www.felix.beldesign.de/




More information about the KDevelop-devel mailing list