Results 1 to 3 of 3

Thread: vector of objects

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default vector of objects

    Hi I need an hint; I need a vector of an object myObj; its size are from 1 to 8; but I should must delete object also; so I'm thinking to use vector <myObj> obj; but its use is that: I must delete object in evey position of vector (ie elemet 4 and not destroy 5,6,7,8). Furthermore I need to know the index of element; Do I use a map? What's better for this?
    Thanks
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: vector of objects

    If you don't require indexes of element to be constant, you can use a vector or a list (if you think you'll be removing elements from the middle very often, it's better to use a list). Otherwise use a map.

  3. #3
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Thanks
    16
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: vector of objects

    You might also consider the std::deque. It has better performance than the std::vector ... especially with deletions ... and still maintains the indexing capability that you lose with std::list.

    You could use the std::map, but I wouldn't if all you need is an indexing capability.

Similar Threads

  1. objects modelling
    By mickey in forum General Discussion
    Replies: 1
    Last Post: 12th April 2008, 08:14
  2. Ole objects in Qt(MS OFFice)
    By mchara in forum Qt Programming
    Replies: 9
    Last Post: 26th September 2007, 07:07
  3. Custom objects in a QGraphicScene
    By draand in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 11:31
  4. static objects in libraries
    By Rawk in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2007, 19:03
  5. dealing individual objects
    By kingslee in forum General Programming
    Replies: 9
    Last Post: 15th November 2006, 01:28

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.