Results 1 to 7 of 7

Thread: Templates Confusion

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: Templates Confusion

    My problem is that in my class template method
    Qt Code:
    1. template <typename T> void MyQueue<T>::Print(){
    2. std::vector <double>::iterator It1;
    3. It1 = data.begin();
    4. for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
    5. cout << " " << *It1<<endl;
    6. }
    To copy to clipboard, switch view to plain text mode 

    this will only work for doubles since It1 is instantiated with doubles. I wanted to change this so that it will work on any T.

    and the only thing i can think of is using special template and give each type a print method

    baray98
    Last edited by jacek; 23rd November 2008 at 20:41. Reason: added missing line breaks

Similar Threads

  1. close() function confusion
    By iamjayanth in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2008, 10:45
  2. Little confusion Regarding general Initilizaion..!!!
    By kunalnandi in forum General Programming
    Replies: 19
    Last Post: 11th October 2008, 12:29
  3. Little confusion Regarding general Initilizaion.. :confused:
    By kunalnandi in forum General Programming
    Replies: 2
    Last Post: 19th September 2008, 10:06
  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.