Thread: Error with a vector

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I acutally though vectors did allocate memory on a need-for basis.
    Yes, but most implementations will err on the assumption that growth is expected. If an allocation is required, for example, the capacity might be doubled on the assumption that if one item is added, another (or more) will also be added.

    >Here it gives the same error:
    It looks like you're making this a lot harder than necessary.
    My best code is written with the delete key.

  2. #17
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    front() returns the value of the first element, so I think it's obvious where that error is coming from. If it's anything but 0 or -1, you have a problem.
    Sent from my iPadŽ

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    57
    edited (dumb question ¬&#172

  4. #19
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Just i... starting at 0 going to size() - 1.
    Sent from my iPadŽ

  5. #20
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >so is there anything that i can use inside the "at", so i can increase indexes in the loop.
    What are you trying to do anyway? I'm willing to bet that there's a much better way to do it if you'll tell us the problem you want to solve.
    My best code is written with the delete key.

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    57
    Oh thanks, you saw the post before i edit it =]
    Now my problem is solved
    (Wow, you guys answer too quick =])

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 10:38 AM
  3. Vector class
    By Desolation in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 05:44 PM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 12:34 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM