I have a vector of structures called "Cell", which contains a position (x, y), radius, and some other variables. I need to add more cells to the end of my vector during the program execution as I loop over the vector and check a condition. Is it safe to create new cells inside the loop and add them to the vector with push_back? Or will this create memory problems as the struct is destroyed(is it?) after the loop is over? the code is more or less the following:
for (Cell c : cells) {
if (my_condition) {
Cell newc;
// define cell properties
cells.push_back(newc);
}
}
thanks in advance