0

I've look on several other SE posts to see if they are similar to my problem, but far as I can see, they are not.

I am doing a binary search tree as part of an assignment for my class. My add function is throwing an & l-value required error, and I have no idea why.

bool addNodeToNode(T data, NodeInterface<T>** cNode) {
    if ((*cNode) == nullptr || cNode == NULL) {
        (*cNode) = new Node<T>(data);
        return true;
    }

    int nodeData = (*cNode)->getData();
    if (data == (*cNode)->getData()) return false;
    //error thrown on the following 2 lines
    if (data < nodeData) addNodeToNode(data, &(*cNode)->getLeftChild());
    if (data > nodeData) addNodeToNode(data, &(*cNode)->getRightChild());
    return true;
};

From what I understand, this error is thrown when the left or right value cannot be assigned to the other value, but I am not assigning anything. What really confuses me is that the == operator does not throw an error.

If it is relavent information, getData(), getRightChild() and getLeftChild() return constant pointers.

xaxxon
  • 19,189
  • 5
  • 50
  • 80
chargerstriker
  • 486
  • 1
  • 5
  • 20
  • What is the actual error text? – NathanOliver Aug 10 '18 at 20:26
  • error C2102: '&' requires l-value – chargerstriker Aug 10 '18 at 20:27
  • You can only get the address of objects that have a fixed physical presence in memory. When you pass the result of a function into the parameter of another function, this is done in a temporary object which does not have a physical address, hence the inability to use the `&` operator. – vdavid Aug 10 '18 at 20:38

0 Answers0