0

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.

3
  • 2
    Have you checked if root is nullptr? How about root->st? Commented Jun 23, 2015 at 12:22
  • that doesn look like a binary tree. Commented Jun 23, 2015 at 12:24
  • Thanks! I forgot to check if the root is NULL. Commented Jun 23, 2015 at 12:25

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.