无效的参数候选者是:'....'

时间:2017-01-05 09:13:03

标签: c++ hashtable

我有以下哈希表插入函数;

template<class T>
void Hash<T>::Insert(int key, const T& value) {

    int index = key % tableSize;
    HashNode<T> node(key, value);
    array[index]->insert(key,node);
    numOfElements++;
    // Check if need to rehash and do it
    Rehash();

}

我想在这段代码中使用它:

StatusType Department::AddMagi(int MagiID,int MagiLevel){
    if(MagiID <=0 || MagiLevel <=0) return INVALID_INPUT;
    Magi magiToInsert(MagiID,magiCount,MagiLevel);
    try{
        hash.Insert(MagiID,magiToInsert);
        magiRank.insert(magiCount,magiToInsert);
    }catch(Tree<int,HashNode<Magi> >::ElementAlreadyExists& e){
        return FAILURE;
    }catch(RankTree<int,Magi>::ElementAlreadyExists& e){
        return FAILURE;
    }
    return SUCCESS;
}

编辑:这是班级部门:

class Department {
    int magiCount;
    Hash<Magi> hash;
    RankTree<int,Magi> magiRank;
    UnionFind creatureAreas;

public:
    Department(int n, int* Levels);
    StatusType AddMagi(int MagiID, int MagiLevel);
    StatusType RemoveMagizoologist(int MagiID);
    StatusType RemoveBarrier(int Creature1, int Creature2);
    StatusType AssignMagizoologistToCreature(int CreatureID);
    StatusType ReleaseMagizoologist(int MagiID);
    StatusType GetCreatureOfMagi(int MagiID, int* CreatureID) const;
    StatusType AreCreaturesInSameArea(int Creature1, int Creature2,
            bool* SameArea) const;
    StatusType GetSizeOfArea(int CreatureID, int* SizeOfArea) const;
};

编辑:一个完全正常的简单测试用例。

class Magi{
int id;
public:
    Magi(int id):id(id){}
    ~Magi(){}
    int getId() const{
        return this->id;
    }
    bool operator==(const Magi& magi){
        return this->id == magi.id;
    }
};

bool InsertTest(){
    bool returnValue = true;
    Magi m1(1);
    Hash<Magi> hash;
    hash.Insert(m1.getId(),m1);
    returnValue = (hash.Find(1) == m1);
    try{
        hash.Insert(m1.getId(),m1);
    }catch(Tree<int,HashNode<Magi> >::ElementAlreadyExists& e){
        returnValue = true;
    }
    Magi m2(12);
    hash.Insert(m2.getId(),m2);
    returnValue = (hash.Find(12) == m2);
    return returnValue;
}

在hash.insert(...)我收到此错误:“无效的参数” 候选人是: void Insert(int,const Magi&amp;) “” 我已经在像这样的类上多次测试了哈希表,从来没有得到过这个错误,我错过了什么?

0 个答案:

没有答案
相关问题