函数作为另一个函数错误的参数 - C++
function as a parameter to another function error - c++
我有以下功能:
CompareType CompareByCitizensNum(const City& c1, const City& c2) {
if (c1.getNumCitizens() > c2.getNumCitizens()
|| ((c1.getNumCitizens() == c2.getNumCitizens())
&& (c1.getCityId() > c2.getCityId()))) {
return BIGGER;
} else if (c1.getCityId() == c2.getCityId()) {
return EQUALS;
}
return SMALLER;
}
这是需要使用此功能的方法:
avlTreeVertix(City newKey, avlTreeVertix* fatherToBe,
CompareType (*compare)(const City&, const City&)) :
bf(0), key(newKey), RightHigh(0), LeftHigh(0), vertexesInSubTree(1), father(
fatherToBe), childL(NULL), childR(
NULL), compare(compare) {
CHECK_NULL(father,);
if (compare(key, father->key) == BIGGER) {
//if (isGreater(father)) {
father->childR = this;
} else {
father->childL = this;
}
}
我尝试通过以下行调用它:
rankTree = new avlTreeVertix(c, NULL, CompareByCitizensNumx);
但是它说:
no matching function for call to wet2::avlTreeVertix::avlTreeVertix(wet2::City&, NULL, <unresolved overloaded function type>)
有什么想法吗?
谢谢!
好的伙计们,问题是该函数是一个成员函数,所以我需要在函数声明中添加一个 "static",现在它可以工作了!骗我..
我有以下功能:
CompareType CompareByCitizensNum(const City& c1, const City& c2) {
if (c1.getNumCitizens() > c2.getNumCitizens()
|| ((c1.getNumCitizens() == c2.getNumCitizens())
&& (c1.getCityId() > c2.getCityId()))) {
return BIGGER;
} else if (c1.getCityId() == c2.getCityId()) {
return EQUALS;
}
return SMALLER;
}
这是需要使用此功能的方法:
avlTreeVertix(City newKey, avlTreeVertix* fatherToBe,
CompareType (*compare)(const City&, const City&)) :
bf(0), key(newKey), RightHigh(0), LeftHigh(0), vertexesInSubTree(1), father(
fatherToBe), childL(NULL), childR(
NULL), compare(compare) {
CHECK_NULL(father,);
if (compare(key, father->key) == BIGGER) {
//if (isGreater(father)) {
father->childR = this;
} else {
father->childL = this;
}
}
我尝试通过以下行调用它:
rankTree = new avlTreeVertix(c, NULL, CompareByCitizensNumx);
但是它说:
no matching function for call to
wet2::avlTreeVertix::avlTreeVertix(wet2::City&, NULL, <unresolved overloaded function type>)
有什么想法吗? 谢谢!
好的伙计们,问题是该函数是一个成员函数,所以我需要在函数声明中添加一个 "static",现在它可以工作了!骗我..