So I have a function which sets a variable in a vector and returns a modifiable cell reference back. But I'm unsure if I am using the reference '&' correctly as I have two examples that work. Ex1:
Cell& Grid::set(const int x, const int y, const Cell & value) {
int index = get_index(x, y);
this->grid[index] = value;
return this->grid[index];
}
Ex2:
Cell& Grid::set(const int x, const int y, const Cell value) {
int index = get_index(x, y);
this->grid[index] = value;
return this->grid[index];
}
Which would be the correct way and how can I tell for the future?
Edit: Cell is an enum not an object