realloc() can move the memory block so you need to return the pointer to the calling function.
here I use realloc()...what's wrong?
void AddInspectedNode(int idxNode, int *Inspected, int *nInspected)
{
(*nInspected)++;
Inspected = (int *) realloc(Inspected, (*nInspected) * sizeof(int));
Inspected[(*nInspected)-1]= idxNode;
}
void AddInspectedNode(int idxNode, int *Inspected, int *nInspected)
{
(*nInspected)++;
Inspected = (int *) realloc(Inspected, (*nInspected) * sizeof(int));
Inspected[(*nInspected)-1]= idxNode;
}
To copy to clipboard, switch view to plain text mode
I've changed the Graph destructor into:
Graph::~Graph()
{
for (int i = 0; i<nNodes;i++)
delete [] mat[i]; //THIS CHANGED
delete [] mat;
}
Graph::~Graph()
{
for (int i = 0; i<nNodes;i++)
delete [] mat[i]; //THIS CHANGED
delete [] mat;
}
To copy to clipboard, switch view to plain text mode
and the CheckPath method of Graph:
int Graph::CheckPath(int idxEntry, int idxExit)
{
int result, nInspected, *Inspected, i;
result = nInspected=0;
Inspected = new int[1];
PathExists(idxEntry, idxExit, mat, nNodes, Inspected, &nInspected, &result);
delete [] Inspected;
//DON'T NEED TO DEALLOCATE HERE THE MATRIX
/* for (i=0; i<nNodes; i++)
delete [] mat[i];
delete [] mat;
*/
return result;
}
int Graph::CheckPath(int idxEntry, int idxExit)
{
int result, nInspected, *Inspected, i;
result = nInspected=0;
Inspected = new int[1];
PathExists(idxEntry, idxExit, mat, nNodes, Inspected, &nInspected, &result);
delete [] Inspected;
//DON'T NEED TO DEALLOCATE HERE THE MATRIX
/* for (i=0; i<nNodes; i++)
delete [] mat[i];
delete [] mat;
*/
return result;
}
To copy to clipboard, switch view to plain text mode
but still get the error...
Bookmarks