2013-10-13 4 views
1

나는 템플릿 클래스 threadBinaryTree 및 기능NULL이 템플릿 인수와 일치하지 않습니까?

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

을 선언하지만, 오류 준수 :

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

pre 필요가 내가 어떻게해야합니까, NULL로 초기화되어야한다?

+1

같은 const가 아닌 사용자가 변수를 제공 할 필요 참조, 뭔가? ''NULL''은 내가 아는 한 C++이 아닙니다. –

+0

코드의 서명에서 pre는 기존 포인터를 참조해야합니다. – Ashalynd

+2

@Jonas'NULL'은 C stdlib에 있기 때문에 C++에 있습니다. 'nullptr'은 더 나은 과부하 해결 동작 때문에 선호됩니다. – rubenvb

답변

4

두 번째 인수는 일종의 포인터에 대한 비 const lvalue 참조를 취하지 만 rvalue (NULL)를 전달합니다. rvalue를 const가 아닌 lvalue 참조에 바인딩 할 수 없습니다.

threadBinaryTreeNode<T>* p = NULL; 
x.inThread(somePtr, p); 
1

두 번째 인수는 threadBinaryTreeNode<T>*& pre 그래서 당신이 그것에 NULL를 통과 할 수있다 : 당신은 좌변을 통과해야합니다.

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

또한, NULL보다는 0nullptr를 사용하는 것이 좋습니다. 함수에 두 번째 인수 이후

0

는``nullptr``를 시도이

threadBinaryTreeNode<char>* ptr = NULL; 
inThread(..., ptr); 
관련 문제