PDA

View Full Version : QList with "local type"



drhex
10th April 2007, 23:06
#include <QList>

int main(int , char ** )
{
struct Foo {
int bar;
};

QList<Foo> foo;
return 0;
}

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?

aamer4yu
11th April 2007, 06:07
Somewhere I found this -


C++ Standard 14.3.1.2
A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.

These might help u further..
http://www.codeguru.com/forum/archive/index.php/t-340574.html
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1353.html