我创建了使用由给定的代码包含一个字符和一个字符串C++二叉树超载
struct M2E
{ char english;
string morse;}
一个stuct,我创建M2E的二进制树是二叉树 ,但我想在字符串这些M2Es排序为了莫尔斯(“*”小于“ - ”) 所以我做了算子在结构M2E超载
bool operator == (M2E& other) const
{
return morse.compare(other.morse);
}
,但我继续给下面的错误消息时,即时通讯compling
no match for "operator ==" in ((binNode<M2E>*)this)->binNode<M2E>::nodeData == dataItem
note:candidates are :bool M2E::operator==(M2E&) const
我使用二进制树的代码是bintree.h是:
template <typename dataType> class bintree
{
private:
binNode<dataType> *root;
int numItems;
void insert(const dataType& newData)
{
// insert the newData into the tree
if (root == NULL)
{
root = new binNode<dataType>(newData);
}
else
{
root->insert(root, newData);
}
numItems++;
}
使用二进制节点的编码IM是binnode.h是:
template <typename dataType> class binNode
{
private:
// private data ====================================
dataType nodeData;
binNode<dataType> *left, *right;
void insert(binNode<dataType>* &root, const dataType& dataItem)
{
if (nodeData == dataItem)
{
throw std::invalid_argument("dataItem already in tree");
}
if (dataItem < nodeData)
{
if (left == NULL)
{
left = new binNode(dataItem);
}
else
{
left->insert(left, dataItem);
}
}
else
{
if (right == NULL)
{
right = new binNode(dataItem);
}
else
{
right->insert(right, dataItem);
}
}
rebalance(root);
}
THX的帮助
实际上我把另一个重载运算符>除非你使用Visual Studio这是不工作的,以及 –