C++11 我将如何处理这些返回类型错误?(hashmap/表) \ifndef HASHMAP\u H #定义HASHMAP_H #包括 #包括 #包括 使用名称空间std; 枚举状态{打开、活动、停用}; //模板 模板 类哈希映射{ 私人: 类节点{ 公众: 常

C++11 我将如何处理这些返回类型错误?(hashmap/表) \ifndef HASHMAP\u H #定义HASHMAP_H #包括 #包括 #包括 使用名称空间std; 枚举状态{打开、活动、停用}; //模板 模板 类哈希映射{ 私人: 类节点{ 公众: 常,c++11,hashmap,hashtable,C++11,Hashmap,Hashtable,我将如何处理这些返回类型错误?(hashmap/表) \ifndef HASHMAP\u H #定义HASHMAP_H #包括 #包括 #包括 使用名称空间std; 枚举状态{打开、活动、停用}; //模板 模板 类哈希映射{ 私人: 类节点{ 公众: 常量字符串键; //向量值; T值; 地位; 节点(字符串键,T val):键(键),值(val),状态(活动){} void运算符=(常量节点&n){ 字符串*ptr; ptr=(字符串*)(&(此->键)); *ptr=n.键; //节点(n

我将如何处理这些返回类型错误?(hashmap/表)
\ifndef HASHMAP\u H
#定义HASHMAP_H
#包括
#包括
#包括
使用名称空间std;
枚举状态{打开、活动、停用};
//模板
模板
类哈希映射{
私人:
类节点{
公众:
常量字符串键;
//向量值;
T值;
地位;
节点(字符串键,T val):键(键),值(val),状态(活动){}
void运算符=(常量节点&n){
字符串*ptr;
ptr=(字符串*)(&(此->键));
*ptr=n.键;
//节点(n);
此->状态=n状态;
此->值=n.value;
}
节点():状态(打开){}
节点(常量字符串和键):键(键),状态(活动){}
//节点(const Node&n):值(n.val),状态(n.status){
};
//typedef映射<
无符号整数散列(常量字符串&s,整数表大小){
无符号整数h=0;
/*每个(s)*/
对于(自动it:s)h=31*h+无符号(it);
返回h%表大小;
}
无符号整数散列(常量字符串(&s){
返回散列(s,表大小);
}
int table_size=103;
向量表;
typedef typename向量::迭代器iter;
公众:
//默认构造函数
hashmap(){
表=向量(表大小);
}
//复制构造函数
hashmap(常量hashmap&x){
table=x.table;
//for(自动it=)
}
//赋值运算符//已被删除
hashmap&运算符=(常量hashmap&x){
此->表.erase(此->表.begin(),此->表.begin()+103);
对于(int i=0;i表。推回(x.table.at(i));
}
归还*这个;
}
//析构函数
~hashmap(){
表1.clear();
}
//索引运算符
T运算符[](常量字符串x)(&T){
inth=hash(x,table.size());
if(表[h]。键==x){
返回值(表[h]。值);
}
否则{
节点*n=新节点(x);
表[h]=*n;
返回值(表[h]。值);
}
} 
//节点测试
void ok(常量字符串x,int i){
节点*temp=新节点(x,i);

cout status
&table[h]
不是迭代器;用
table替换它。begin()+h
NULL
也不是迭代器,事实上,迭代器没有通用的“nota valid value”常量,就像
NULL
用于指针一样。
table.end()
最接近。在另一个类中定义一个类有什么特别的原因吗?但这不是你的代码中的问题。@IgorTandetnik我建议你重新发布你的评论作为答案。这类问题基本上是要求其他人免费调试源代码。因为你花时间查看OP(冗长且格式不正确)源代码你至少应该为解决他的问题而得到赞扬。@Barracuda很抱歉,我的问题是这样产生的。我并没有那么了解情况,尤其是迭代器、指针和引用。所以我被难住了。但是你建议我如何更好地格式化我的代码?@坚持你不应该发布冗长的源代码。使用调试器来查看专业代码的位置问题正是如此,如果您在理解某些内容时遇到困难,而其他地方或此处没有帮助,请提出问题。您的问题可以通过阅读标准库文档和/或C/C++书籍轻松解决。
#ifndef HASHMAP_H
#define HASHMAP_H
#include <iostream>
#include <string>
#include <vector>

using namespace std;

enum Status{open , active, deactivated };

//template <typename T>


template</*typename Key,*/ typename T>
class hashmap{
private:
    class Node{
    public:
        const string Key;
        //vector<T> values;
        T value;
        Status status;
        Node(string key, T val) :Key(key), value(val), status(active){}

        void operator =(const Node &n){
            string *ptr;
            ptr = (string*)(&(this->Key));
            *ptr = n.Key;
            //Node(n);
            this->status = n.status;
            this->value = n.value;
        }
        Node() :status(open){}

        Node(const string& key) :Key(key), status(active){}
        //Node(const Node &n) : value(n.val), status(n.status){}


    };
    //typedef map<
    unsigned int hash(const string& s, int tableSize){
        unsigned int h = 0; 
        /*each(s)*/ 
        for(auto it : s) h = 31 * h + unsigned(it);
        return h % tableSize;
    }

    unsigned int hash(const string& s){
        return hash(s, table_size);
    }

    int table_size = 103;
    vector<Node> table;

    typedef typename vector<Node>::iterator iter;

public:
    //default constructor
    hashmap(){
        table = vector<Node>(table_size);
    }
    //copy constructor
    hashmap(const hashmap& x){
        table = x.table;
        //for (auto it = )
    }
    //assignment operator //has been removed
    hashmap& operator=(const hashmap& x){
        this->table.erase(this->table.begin(), this->table.begin() + 103);
        for ( int i = 0; i < x.table_size; i++){
            this->table.push_back(x.table.at(i));
        }
        return *this;
    }
    //destructor
    ~hashmap(){
        table.clear();
    }

    //index operator
    T& operator[](const string x){
        int h = hash(x, table.size());

        if (table[h].Key == x){
            return (table[h].value);
        }
        else {
            Node* n = new Node(x);
            table[h] = *n; 
            return (table[h].value);
        }
    } 

    //Node test
    void okay(const string x,int i){
        Node *temp = new Node(x, i);
        cout << temp->status << endl;
        /*cout << table[1].status << endl;
        cout << table[2].status << endl;
        table.at(0) = (*temp);
        cout << table[0].Key << endl;
        cout << table[0].value << endl;
        cout << table[3].status << endl;*/

    }

int stride(int x){
            return (7-x%7);
        }

    //find()
    iter find(const string& x){
        int h = hash(x);
        int s = stride(h);
        int t = table_size; 
        int z;
        //for (int i = 0; i < t; i++){
        for (int i = hash(x, table_size) % t; i != t; i = (i + stride(h)) % t){
            z = (h + i*s) % table_size;
            if (table[z].status == open) return NULL;
            if (table[z].status == deactivated) continue;
            if (table[z].Key == x) return &table[h];
        }

        return table.end();
    }

    //begin()
    iter begin(){
        return table.begin();
    }
    //end()
    iter end(){
        return table.end();
    }

};



#endif // !HASHMAP_H
    Error2error C2664: 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<hashmap::Node>>>::_Vector_iterator(const 
std::_Vector_iterator<std::_Vector_val<std::_Simple_types<hashmap::Node>>> &)' : cannot convert argument 1 from 'hashmap<int>::Node *' to 'const 
std::_Vector_iterator<std::_Vector_val<std::_Simple_types<hashmap<int>::Node>>> &' 

    Error1error C2664: 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<hashmap<int>::Node>>>::_Vector_iterator(const 
std::_Vector_iterator<std::_Vector_val<std::_Simple_types<hashmap<int>::Node>>> &)' : cannot convert argument 1 from 'int' to 'const 
std::_Vector_iterator<std::_Vector_val<std::_Simple_types<hashmap<int>::Node>>> &'