Не в состоянии добавить указатель на вектор в C ++C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Не в состоянии добавить указатель на вектор в C ++

Сообщение Anonymous »

Я пытаюсь внедрить систему сетки для обнаружения столкновений между танками в игре. Танк должен находиться в правой ячейке сетки, сохраненной и обновляемой всякий раз, когда он переходит к другому. vec2 position{ start_blue_x + ((i % max_rows) * spacing), start_blue_y + ((i / max_rows) * spacing) };
Cell* tank_cell = Cell::find_cell_for_tank(position.x, position.y, cells);
Tank tank = Tank(position.x, position.y, BLUE, tank_cell, &tank_blue, &smoke, 1100.f, position.y + 16, tank_radius, tank_max_health, tank_max_speed);
tank_cell->tanks.push_back(&tank);
< /code>
cell.h:
Cell(int column, int row, vector tanks);
< /code>
It seems to happen at the last line where I push the tank in the cell.

Exception thrown: Access violation reading

Cell::find_cell_for_tank()
Cell* Cell::find_cell_for_tank(int pos_x, int pos_y, vector& cells)
{
int tank_col = pos_x / CELL_WIDTH;
int tank_row = pos_y / CELL_HEIGHT;

for (int i = 0; i < cells.size(); i++) {
if ((*cells.at(i)).column == tank_col && (*cells.at(i)).row == tank_row)
{
return cells.at(i);
}
}

Cell* new_cell = &Cell(tank_col, tank_row, {});
cells.push_back(new_cell);
return new_cell;
}


Подробнее здесь: https://stackoverflow.com/questions/756 ... ector-in-c
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»