【发布时间】:2011-10-12 21:19:53
【问题描述】:
比较两个字符串时出现此错误(使用重载运算符)。
错误发生在这里:
void addEtu(node *Node, element *Etu){
if (Node->Value == NULL)
Node->Value = Etu;
else{
if (Node->left == NULL && *Node > *Etu) //This line specifically
Node->left->Value = Etu;
else if (Node->left != NULL && *Node->left < *Node)
addEtu(Node->left, Etu);
else if (Node->right == NULL)
Node->right->Value = Etu;
else
addEtu(Node->right, Etu);
}
}
并重定向到 iosfwd;具体到这个功能:
static int __CLRCALL_OR_CDECL compare(const _Elem *_First1, const _Elem *_First2,
size_t _Count)
{ // compare [_First1, _First1 + _Count) with [_First2, ...)
return (_CSTD memcmp(_First1, _First2, _Count));
}
node 是一个包含另外两个节点和“value”的结构,一个包含一些字符串的结构。 重载如下:
bool operator>(const node& V1, const node& V2){
if (V1.Value->Code > V2.Value->Code)
return true;
return false;
}
函数addEtu带入参数的节点是(二叉树的)根,初始化如下:
void Initialize(node *Root){
Root->right = NULL;
Root->left = NULL;
Root->Value = NULL;
}
错误发生在第二次调用 addEtu 时。
我不知道出了什么问题,我在 Google 上搜索了大约一个小时,没有发现与我的具体错误相关的任何内容,感谢您的帮助。
【问题讨论】:
标签: c++