Qt Code:
  1. #include <QList>
  2.  
  3. int main(int , char ** )
  4. {
  5. struct Foo {
  6. int bar;
  7. };
  8.  
  9. QList<Foo> foo;
  10. return 0;
  11. }
To copy to clipboard, switch view to plain text mode 

This short program fails to compile for me (using gcc-4.1.0):

prog.cc: In function 'int main(int, char**)':
prog.cc:9: error: 'main(int, char**)::Foo' uses local type 'main(int, char**)::Foo'
prog.cc:9: error: trying to instantiate 'template<class T> class QList'
prog.cc:9: error: invalid type in declaration before ';' token


I can get it to compile by declaring the struct outside the method were it will be used, but since I only need it on one method it feels natural to declare it there.

Not sure if this is a Qt problem or a gcc problem. Is there anyone who knows why you can't make a list of a locally declared struct?