terminate called after throwing instance std::bad_alloc

hey guys am having a problem with my code....am creating a game called defenders for my software development 2 project.....so forgive me i cant post my entire code due to plagerism and dont want my fellow class mates to google and it...my code was working fine bt after some time i get error "terminate called after throwing instance std::bad_alloc" and am guessing its because my 2 vector containers are passed by value, hence i ran out of memory i guess....bt i tried passing it by reference bt gves me an error iter,bulletarray,iter1,enemyarray referenced bt not initialized...dnt knw wat to do please help....and thanx in advance...below is how i referenced my vectors

1
2
3
4
5
  vector<bullet>::const_iterator  &iter;
    vector<bullet> &bulletArray; 

vector<enemy>::const_iterator &iter1;
    vector<enemy> &enemyArray;
vector<bullet> &bulletArray; ; what bulletArray refers to? You must point reference to something, or it would be useless.
Passing iterator by reference is useless, they are intended to be passed by value.

It is really hard to get bad_alloc. You must have some memory leaks or simply unused memory hogging up space. How much your application consumes usually?
i dont understand wat you mean by "How much your application consumes usually?" am using codeblocks 12.11
Last edited on
i dont understand wat you mean by "How much your application consumes usually?"
I asked how much memory it consumes when run. (althrough it is really hard to get bad_alloc. Your program will hang much earlier).

Most likely you made an error somewhere and are trying to allocate several gigabytes at once (which will exaust adress space in 32bit application)
do u have any suggestions for this......again thanx for the reply
do u have any suggestions for this
For what?
Referece problem? Initialize it to whichever you want to point them to.
bad_alloc? I suggest running it under debugger and fincting which line causes this problem.
You are probably trying to allocate a huge block of memory. Run it in a debugger and see where that bad_alloc is being thrown from. Check how much space you're trying to allocate.
Topic archived. No new replies allowed.