title: Cannot declare map with integer keys in C++
body: <p>I was attempting to write a Longest Common Substring program using Rabin Karp and Binary search. For that I wrote a method which basically create a hash table for one of the strings and the key would be the hash value of the pattern of length M starting at index i . The value of they key would be index i .</p>
  
  <p>I have written the following code :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include&lt;map&gt;
  #include&lt;math.h&gt;
  #define BASE 10
  #define BASE2 10.0
  #define M 99999989
  using namespace std;
  map&lt;int, int&gt; hashmap;
   int pHash=0;
   int mod(int a, int b) {
      return (a%b + b)%b;
  }
   int getHash(string &amp; pattern) {
       int hashVal = 0;
      for ( int i =0 ; i&lt;pattern.length();i++) {
              int val = (int) pattern[i];
              hashVal = mod(hashVal*BASE + val, M);
  
      }
  
      return hashVal;
  }
  int rabinKarp(string &amp;pattern, string &amp; text)
  {
       pHash = getHash(pattern);  
       cout&lt;&lt;"P HASH  : "&lt;&lt;pHash&lt;&lt;endl;
       int m = pattern.size();
       int fHash = getHash(text.substr(0, pattern.size()));
      int  newKey = fHash;
       hashmap.insert(newKey, 0);
       if(fHash==pHash)
              cout&lt;&lt;"Rabin Karp found a match at index : 0 "&lt;&lt; endl;
  
  
       for(int i = 1; i &lt;=text.size()-pattern.size();i++) {
          int val = (int)text[i-1];
          double sz = (double)pattern.size()-1.0;
          int temp = pow(BASE2, sz);
          int mult= mod(temp,M);
          fHash = mod(fHash - mod(val*mult,M),M);
          fHash= mod(fHash*BASE, M);
          fHash= mod(fHash+(int)text[i+m-1], M);
          int key = fHash ;
          hashmap.insert(key, i);
          if(fHash==pHash)
              cout&lt;&lt;"Rabin Karp found a match at index : "&lt;&lt; i&lt;&lt;endl;
      }
      return 1;
  
  }
  int main() {
      string pattern;
      string text;
      cout&lt;&lt;"Please enter the pattern "&lt;&lt;endl;
      getline(cin, pattern) ;
      cout&lt;&lt;"Please enter the text " &lt;&lt;endl;
      getline(cin, text);
      int index = rabinKarp(pattern, text) ;
  
  }
  </code></pre>
  
  <p>The problem is that I am unable to insert the keys into the map . I am getting the following error of which I can make no sense . Anyone can help me understand what this is ?</p>
  
  <p>Error   3   error C2664: 'std::pair&lt;_Ty1,_Ty2> std::_Tree&lt;_Traits>::insert(const std::pair&lt;_Kty,_Ty> &amp;)' : cannot convert parameter 1 from 'int' to 'const std::pair&lt;_Ty1,_Ty2> &amp;'  c:\program files\microsoft visual studio 9.0\vc\include\xtree   760 SPOJ</p>
  
  <p>Error   2   error C2100: illegal indirection    c:\program files\microsoft visual studio 9.0\vc\include\xtree   760 SPOJ</p>