Results 1 to 3 of 3

Thread: help with templates please

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: help with templates please

    Qt Code:
    1. QMap<T,QString>::iterator it;
    To copy to clipboard, switch view to plain text mode 
    Because compiler does not know that "iterator" is a typename. You need to specify that:
    Qt Code:
    1. typename QMap<T,QString>::iterator it;
    To copy to clipboard, switch view to plain text mode 

    ----------------
    I see that g++ (v 4.5.2) produces a nice message:
    Qt Code:
    1. template <class C> class Test{
    2. public:
    3. void fun();
    4. };
    5.  
    6. template<class C> void Test<C>::fun(){
    7. C::iterator it;
    8. }
    9.  
    10. // error: need 'typename' before 'C:: iterator' because 'C' is a dependent scope
    To copy to clipboard, switch view to plain text mode 
    Last edited by stampede; 4th February 2011 at 17:27. Reason: additional comment

  2. The following user says thank you to stampede for this useful post:

    GrahamLabdon (7th February 2011)

Similar Threads

  1. Templates Confusion
    By baray98 in forum General Programming
    Replies: 6
    Last Post: 23rd November 2008, 11:14
  2. operator<< and templates
    By mickey in forum General Programming
    Replies: 3
    Last Post: 30th May 2008, 17:13
  3. templates
    By mickey in forum General Programming
    Replies: 5
    Last Post: 16th January 2008, 15:25
  4. dynamic_cast and templates
    By KShots in forum General Programming
    Replies: 7
    Last Post: 7th August 2007, 20:01
  5. Templates : Help Please
    By sunil.thaha in forum General Programming
    Replies: 4
    Last Post: 14th February 2006, 13:50

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
  •  
Qt is a trademark of The Qt Company.