_stuckVertices
is an array of pointers and I would like to update one index of that array without using _stuckVertices[ (row * _cols) + column ]
3 times. The reason it is an array of pointers is because the vast majority of the time the pointer will be NULL. The following code works but I need to dereference a each time I use it:
void Cloth::stickPoint(int column, int row)
{
Anchor **a = &_stuckVertices[ (row * _cols) + column ];
if (!*a)
*a = new Anchor(this, column, row);
(*a)->stick();
}
I originally had it written like this, but the _stuckVertices pointer doesn't get updated:
void Cloth::stickPoint(int column, int row)
{
Anchor *a = _stuckVertices[ (row * _cols) + column ];
if (!a)
a = new Anchor(this, column, row);
a->stick();
}
Is there a way to write Anchor *a = _stuckVertices[ index ]
so that a
is like an alias into the array that I can update, or is something like the first piece of code how I should do this?
Thanks