このエラー:
エラー C2664: 'Set::Set(int (__cdecl *)(ElemType,ElemType))' : パラメーター 1 を 'int (__cdecl *)(CorrectionT &,CorrectionT &)' から 'int (__cdecl *)(ElemType) に変換できません,ElemType)'
この比較関数を BST ベースの SET クラスの一部として実装した結果です。
int compareCorr(struct CorrectionT &a, struct CorrectionT &b)
{
if (a.editDistance < b.editDistance) return -1;
else if (a.editDistance == b.editDistance) return 0;
else return 1;
}
クラスセット
Set(int (*cmpFn)(ElemType, ElemType) = OperatorCmp);
Set での比較関数の使用は追加のためのものです
template <typename ElemType>
void Set<ElemType>::add(ElemType element) {
bst.add(element);
}
そして、bst クラスの restating ヘッダー ファイルを追加します。
BST(int (*cmpFn)(ElemType one, ElemType two) = OperatorCmp);
および関数 add
template <typename ElemType>
bool BST<ElemType>::add(ElemType data) {
bool createdNewNode = false;
recAddNode(root, data, createdNewNode);
if (createdNewNode) timestamp++;
return createdNewNode;
}
template <typename ElemType>
bool BST<ElemType>::recAddNode(nodeT * & t, ElemType & data,
bool & createdNewNode) {
if (t == NULL) {
t = new nodeT;
t->data = data;
t->bf = BST_IN_BALANCE;
t->left = t->right = NULL;
createdNewNode = true;
numNodes++;
return true;
}
int sign = cmpFn(data, t->data);
if (sign == 0) {
t->data = data;
createdNewNode = false;
return false;
}
int bfDelta = 0;
if (sign < 0) {
if (recAddNode(t->left, data, createdNewNode)) {
bfDelta = -1; /* left subtree is higher */
}
} else {
if (recAddNode(t->right, data, createdNewNode)) {
bfDelta = +1; /* right subtree is higher */
}
}
updateBF(t, bfDelta);
return (bfDelta != 0 && t->bf != BST_IN_BALANCE);
}
ここで何が起こっているのか分かりますか - 比較機能の問題は何ですか?