ggaaooppeenngg
ggaaooppeenngg

Reputation: 1383

NULL doesn't match template argument?

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?

Upvotes: 1

Views: 101

Answers (3)

juanchopanza
juanchopanza

Reputation: 227420

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 );

Upvotes: 4

john
john

Reputation: 87959

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);

Upvotes: 0

masoud
masoud

Reputation: 56479

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.

Upvotes: 1

Related Questions