title: Hash table for objects in c++
body: <p>I'm trying to make a hash table for simple objects unfortunately when I compile this code</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  class K {
     public:
        int n;
        K(int n): n(5) {}
  };
  
  class hTab {
        string * a;
        K * k;
        int r;
     public:
        hTab(int n): a(new string[n]), k(new K[n]), r(0) {}
        ~hTab() { delete [] k; delete [] a; }
        int getId(string s) {
           int i = 0;
           while (i != r &amp;&amp; s != a[i]) {++i;}
           return i;
        }
        K &amp; operator [] (string s) {
           a[r] = s;
           ++r;
           return k[r-1];
        }
        const K &amp; operator [] (string s) const {return k[getId(s)];}
  };
  
  int main() {
     hTab tab(20);
     K a(5);
     tab["sth"] = a;
     cout &lt;&lt; tab["sth"].n;
     return 0;
  }
  </code></pre>
  
  <p>following errors pops up.</p>
  
  <pre><code>In constructor 'hTab::hTab(int)'
  16 error: no matching function for call to 'K::K()'
  In member function 'const K&amp; hTab::operator[](std::string) const'
  28 error: passing 'const hTab' as 'this' argument of 'int hTab::getId(std::string)' discards qualifiers [-fpermissive]|
  </code></pre>
  
  <p>I can't figure out what I'm doing wrong. I will be grateful for any kind of help.</p>