Error with a vector

This is a discussion on Error with a vector within the C++ Programming forums, part of the General Programming Boards category; >I acutally though vectors did allocate memory on a need-for basis. Yes, but most implementations will err on the assumption ...

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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,069
    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,069
    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,796
    >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 =])

Page 2 of 2 FirstFirst 12
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, 12:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21