내 바이너리 검색 트리에 대한 재귀 적 삽입 기능을 만들려고합니다. 그러나 다음과 같은 오류가 발생합니다. "Node * 유형의 rvalue 주소를 가져올 수 없습니다." 나는 내 포인터가 NULL이라면 그 주소를 가지고 나에게이 오류를 줄 것이라고 생각하지만 어떻게이 문제를 완화 할 수 있을까?이진 트리에 대한 재귀 함수에서 rvalue 오류의 주소를 가져올 수 없습니다.
참고 : Node (data * _data) 생성자는 개체를 만들 때 왼쪽 및 오른쪽 포인터를 NULL로 설정합니다.
내 코드는 다음과 같습니다. rvalue 오류가 발생하는 두 줄을 주석 처리했습니다. Xcode도 사용하고 있습니다.
미리 감사드립니다.
class Node {
private:
data* data;
Node* left;
Node* right;
public:
Node(data* _data);
~Node();
Node* getLeft(); // gets the left immediate descendent of the Node.
Node* getRight(); // gets the right immediate descendent of the Node
data* getVal(); //returns pointer to data
};
class Tree {
private:
Node* root;
int nodeCount;
Node* placeNode(Node** root, data* data);
public:
Tree();
~Tree();
bool placeIn(data* newData); //placeIns node into ordered BST
};
bool Tree::placeIn(data* newData) {
return placeNode(root, newData); //placeIns newData object into BST
}
Node* Tree::placeNode(Node** root, data* data) {
//placeIns node into BST via in order traversal
if ((*root) == NULL) {
return (*root) = new Node(data);
}
if ((*root)->getVal()->getName() == data->getName()) {
cout << "Node exists" << endl;
return NULL;
}
if ((*root)->getVal()->getName() > data->getName()) {
placeNode(&(*root)->getLeft(), data); //Cannot take the address of an rvalue of type Node*
}
else {
placeNode(&(*root)->getRight(), data); //Cannot take the address of an rvalue of type Node*
}
return NULL;
}
이 코드 때문에 비에 (컴파일되지 않습니다 품질 관련 문제). 오류가 무엇인지 말하지 않으므로 도움을 받기가 매우 어렵습니다. https://godbolt.org/g/RZFQXK – xaxxon
"rvalue error"는 매우 설명 적이 지 않습니다. – xaxxon
코드는 내 프로그램의 단순화 된 버전입니다. 위의 내용을 편집하여 오류를 정확하게 설명합니다. – purpleScrn