好的,所以我正在尝试制作(目前)不平衡的二叉树。我遇到了一个我似乎无法摆脱的奇怪错误。下半场也出现了同样的错误,所以我现在暂时摆脱了它。
void insert( binTreeNode < T >*& node, const T& obj) { // private version of insert( )
if (obj < node->data) {
if(node->left != NULL)
insert(node->left, obj);
else {
binTreeNode<T> n;
n = new binTreeNode(obj, NULL, NULL);
node->left = n;
}
} else {
if(node->right != NULL)
insert(node->right, obj);
else {
}
}
}
和错误
In file included from ../src/binTree.cc:2:0:
../src/binTree.h: In member function 'void binTree<T>::insert(binTreeNode<T>*&, const T&)':
../src/binTree.h:54:16: error: expected type-specifier before 'binTreeNode'
../src/binTree.h:54:16: error: expected ';' before 'binTreeNode'
src/subdir.mk:24: recipe for target `src/binTree.o' failed
make: *** [src/binTree.o] Error 1
binTreeNode 的构造函数定义为
binTreeNode (const T& obj, binTreeNode < T >* leftObj = NULL, binTreeNode < T >* rightObj = NULL) {
left = leftObj;
right = rightObj;
data = obj;
}
谢谢你的帮助。