1

I declared a template class threadBinaryTree and a function

void threadBinaryTree<T>::inThread
     (threadBinaryTreeNode<T>*root,threadBinaryTreeNode<T>*& pre)

but complies error:

no matching function for call to ‘threadBinaryTree<char>::inThread
      (threadBinaryTreeNode<char>*, NULL)’|

pre need to be initialized as NULL, how should I do?

3
  • 1
    Have you tried nullptr? NULL isn't c++ as far as I know. Commented Oct 13, 2013 at 8:46
  • From the signature in code, pre must reference the existing pointer. Commented Oct 13, 2013 at 8:48
  • 2
    @Jonas NULL is in C++ because it is in the C stdlib. nullptr is preferred though because of better overload resolution behavior. Commented Oct 13, 2013 at 9:01

3 Answers 3

4

Your second argument takes a non-const lvalue reference to some kind of pointer, but you are passing an rvalue (NULL). You cannot bind an rvalue to a non-const lvalue reference. You need to pass an lvalue:

threadBinaryTreeNode<T>* p = NULL;
x.inThread( somePtr, p );
Sign up to request clarification or add additional context in comments.

Comments

1

The second argument is threadBinaryTreeNode<T>*& pre so you can not pass NULL to it.

threadBinaryTreeNode<T> *empty = 0; // Pass empty to the method instead of NULL

Also, it's better to use 0 and nullptr rather than NULL.

Comments

0

Since your second argument to your function is a non-const reference you need to supply a variable, something like this

threadBinaryTreeNode<char>* ptr = NULL;
inThread(..., ptr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.