This is a snippet of code I use:
void Move::AddToMovesList(Location* &list, int row, int col) {
// If the list is empty, create the first item
if (list == NULL)
list = new Location(row, col);
// List exists, so append
else
list->Add(row, col);
}
If list is NULL, a new Location should be created and the pointer list should point to that new location. That's the behavior I'd expect from this code, but right before gdb exits this function I noticed that list is still NULL. What am I doing wrong here?
I used the ampersand in Location* &list to make sure that I can permanently (vs. locally) change the supplied pointer.
Location** listand see what happens?Locationis singular, reading it does not make one think of a list. Passing multiple arguments to a list constructor does not make one think that they will all be used to initialize one element and the resulting list will have length one.