Friday 15 May 2015

class - C++ puttting one element of vector to another vector -


I am working on the RTS game using SDL. I have a wooden square whose object is wood from nearby tree In the class, I create a vector which is called temp_tires and as an argument for the constructor, I use a vector of paste objects which I pass.

Woodworking Manufacturer:

  woodyard :: wood (int x, int y, int hp, int id, vector & lt; tree & gt; tree). Vector & lt; Tree & gt; Temp_trees; For (int i = 0; i.sc (); i ++) {if ((tree [i] .xPos - 100) / 50> = x - 5 & (tree [i] .xPos - 100 ) / 50 & lt; = x + 4) {if (([[tree [i]. IPOS - 100) / 50> = y - 5 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ([i] .yPos - 100) / 50 & Lt; = Y + 4) {temp_trees.push_back (tree [i]); }}} Collect_control = 0; No = 0; }   

Collect_wood function:

  zero atmospheres :: collection_wood () {if (not == 5) {temp_trees [collect_control]. Drewno - = 1; If (temp_trees [collect_control]. Drewno & lt; = 0] {collect_control ++; Temp_trees.erase (temp_trees.begin ()); }} No ++; If (no> = 10) {no = 0; }}   

The program crashes when it starts. Can anyone see any error in this code ??

PS: I think there may be something wrong with cutting the elements from one vector to another in the Constructor.

There is no illegal operation in the constructor.

and collect_wood (), although not profane, there is no specific reason to crash it.

What is the value of collect_control ? Do you check that this & lt; Temp_trees.size () ? Being aware of temp_trees.size () keep changing since elements have been erased.

Maybe after the trash, there should not be a rise of collect_control : all elements retreat, and after the erasure, the archive_control is already pointing to the next element.

Note: Consider that temp_trees.erase (temp_trees.begin ()); Disabled things that you can do with a vector (delete the first element).

No comments:

Post a Comment