-1
我正在写一个二叉树,开始收到错误,所以我已经删除了所有的模板,但它仍然不会编译,难倒我最后的错误! 写一个递归的附加功能,但不知道如何到我的新的数据类添加到我的树时,发现一个空的节点错误C2106:'=':左操作数必须是l值C++二进制树
#pragma once
#include <cstring>
typedef dataClass T;
//template <class T>
class treeNode
{
private:
treeNode* _greaterNode;
treeNode* _lessNode;
T _data;
public:
treeNode(T data);
void add(T data);
void del(T data);
};
//template <class T>
treeNode/*<T>*/::treeNode(T data)
{
_data = data;
_greaterNode = _lessNode = NULL;
}
//template <class T>
void treeNode/*<T>*/::add(T data)
{
if(_data == NULL)
{
// add here
this = new treeNode(data);
}
else if(data > _data)
{
// data is bigger go to greater
this->_greaterNode->add(data);
}
else if(data < _data)
{
// data is lower go to less than
this->_lessNode->add(data);
}
else
{
// data the same, throw exception
}
}
它打破:
if(_data == NULL)
{
// add here
this = new treeNode(data);
}
'this'是'treeNode的* const'不能修改。你应该只是做'_data = data'。 – 2012-02-04 19:24:07
In。书房。塔季翁。 – 2012-02-04 19:28:06
而“它破”不是错误描述。 – 2012-02-04 19:28:42