Results 1 to 2 of 2

Thread: QList with "local type"

  1. #1
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QList with "local type"

    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?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList with "local type"

    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/archiv.../t-340574.html
    http://www.open-std.org/jtc1/sc22/wg...002/n1353.html

  3. The following user says thank you to aamer4yu for this useful post:

    drhex (11th April 2007)

Similar Threads

  1. using Qlist with a class
    By Havard in forum Qt Programming
    Replies: 10
    Last Post: 24th February 2007, 20:38
  2. Query about QHash , QList
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2006, 10:04
  3. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 16:27
  4. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 21:43
  5. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 11:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.