I have a problem concerning modifying the elements of a binary tree. This is the error I get: Access violation reading location 0x00000018. I think I'm accessing a null pointer but I don't know how to solve the problem.
This is the code that I used:
void modifyStatus(nod* root)
{
if (root->info.st == done)
root->info.st = reachedDest;
modifyStatus(root->st);
modifySatus(root->dr);
}
I must specify that "done" and "reachedDest" are the elements of an enum.
I think I'm accessing a null pointer but I don't know how to solve the problem.
Check the pointer for NULL
before accessing it:
void modifyStatus(nod* root) {
if (!root) {
return;
}
...
}
Note that calls that look like this modifySatus(root->st);
look like C, not like C++. In situations when you have control over nod
class, you should consider making modifySatus
a member function:
root->modifyStatus();
User contributions licensed under CC BY-SA 3.0