I submitted this program for a class and the error message says that there are a few memory leaks, but I cannot find them (I even asked another professor)
Here is the error message:
==27796== HEAP SUMMARY:
==27796== in use at exit: 160 bytes in 2 blocks
==27796== total heap usage: 192 allocs, 190 frees, 21,989 bytes allocated
==27796==
==27796== 160 bytes in 2 blocks are definitely lost in loss record 1 of 1
==27796== at 0x402ADFC: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==27796== by 0x804D5C2: SweeperGrid::SweeperGrid(SweeperGrid const&) (in /tmp/grading20151030-8173-zfd6af-0/sweepertest)
==27796== by 0x804BF57: main (sweepertest.cpp:357)
And the following is any code where I use new or delete:
// Explicit-value Constructor
SweeperGrid::SweeperGrid(const int initialRows, const int initialCols, const int density){
if ((initialRows<5 || initialCols<5) || (density<25 || density>75)) {
throw out_of_range("Grid not large enough (number of rows or columns cannot be fewer than 5) or density is too low or high (must be between 25% and 75%)");
}
numRows = initialRows;
numColumns = initialCols;
numBombs = 0;
grid = new SweeperCell*[numRows];
for(int i=0; i <numRows; i++){
grid[i] = new SweeperCell[numColumns];
}
srand(time(0));
for(int i=0; i<numRows; i++){
for (int j=0; j<numColumns; j++){
if(rand()%100+1<density){
PlaceBomb(i, j);
}
}
}
}
// Copy Constructor
SweeperGrid::SweeperGrid(SweeperGrid const & source){
numRows=source.GetRows();
numColumns=source.GetColumns();
numBombs=source.GetBombs();
grid = new SweeperCell * [numRows];
for(int i=0; i < numRows; i++){
grid[i] = new SweeperCell[numColumns];
}
for(int i=0; i<numRows; i++){
for (int j=0; j<numColumns; j++){
grid[i][j] = source.At(i, j);
}
}
}
// Destructor
SweeperGrid::~SweeperGrid(){
for(int i=0; i<numRows; i++){
delete [] grid[i];
}
delete [] grid;
}
// Function: Overloaded assignment operator
void SweeperGrid::operator= (SweeperGrid const & source){
numRows=source.GetRows();
numColumns=source.GetColumns();
numBombs=source.GetBombs();
for(int i=0; i<numRows; i++){
delete [] grid[i];
}
delete [] grid;
grid = new SweeperCell * [numRows];
for(int i=0; i < numRows; i++){
grid[i] = new SweeperCell[numColumns];
}
for(int i=0; i<numRows; i++){
for (int j=0; j<numColumns; j++){
grid[i][j] = source.At(i, j);
}
}
}