So you are passing in a local copy of piece... then storing the memory address of a local variable.Code:void board:place(piece p, int x, int y, int z) { table[x][y][z] = &p; }
THIS IS A BIG NO! As soon as the place() function ends, &p is no longer valid.
It should be instead something like,
Go ahead and pass in the original object, not make a copy of it. The original object was created in main(), so it will still be valid through out the end of the program.Code:homeBoard->place(this,c); ....... void board:place(piece *p, int x, int y, int z) { table[x][y][z] = p; }




Reply With Quote
