Thread: STL Vectors of Vectors

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    11

    STL Vectors of Vectors

    Hi all,

    I'm having some trouble getting my head around using a vector of vectors. I was wondering if anyone could set me straight with this - it's been ages since i've used vectors... :/

    Code:
    typedef std::list <Cenemy *> listEnemies;
    std::vector <listEnemies> m_wavesEnemies;
    I am not sure that this is the correct way to add new elements into the array

    Code:
    Cenemy *e = new Cenemy();
    
    m_wavesEnemies.resize(10);
    
    // Then added elements
    m_wavesEnemies[0].push_back(e);
    but i'm more confused about how to read the elements - the following doesn't appear to work and throws up a compiler error:

    Code:
    m_wavesEnemies[0][0];
    Thanks for the help!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You're not using a vector of vectors -- you're using a vector of lists. Lists don't support [array indexing].

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    11
    oh - my - god...
    sorry - this is the end of a 16 hour coding session and i'm not thinking straight. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sets of Vectors in STL
    By Steff in forum C++ Programming
    Replies: 8
    Last Post: 06-18-2009, 12:03 AM
  2. allocating structs within STL vectors
    By aoiOnline in forum C++ Programming
    Replies: 20
    Last Post: 12-05-2007, 02:49 PM
  3. Array of Vectors amd other STL questions
    By kolistivra in forum C++ Programming
    Replies: 16
    Last Post: 04-12-2007, 09:11 AM
  4. STL vectors
    By sand_man in forum C++ Programming
    Replies: 7
    Last Post: 12-06-2005, 01:39 AM
  5. STL Vectors
    By Da-Nuka in forum C++ Programming
    Replies: 2
    Last Post: 02-25-2005, 08:35 PM