title: How can I use std::maps with user-defined types as key?
body: <p>I'm wondering why I can't use STL maps with user-defined classes. When I compile the code below, I get the following cryptic error message. What does it mean? Also, why is it only happening with user-defined types? (Primitive types are okay when they are used as key.)</p>
  
  <blockquote>
    <p>C:\MinGW\bin..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\stl_function.h||In
    member function `bool
    std::less&lt;_Tp>::operator()(const _Tp&amp;,
    const _Tp&amp;) const [with _Tp =
    Class1]':|</p>
    
    <p>C:\MinGW\bin..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\stl_map.h|338|instantiated
    from `_Tp&amp; std::map&lt;_Key, _Tp,
    _Compare, _Alloc>::operator[](const _Key&amp;) [with _Key = Class1, _Tp = int, _Compare = std::less, _Alloc = std::allocator >]'|</p>
    
    <p>C:\Users\Admin\Documents\dev\sandbox\sandbox\sandbox.cpp|24|instantiated
    from here|</p>
    
    <p>C:\MinGW\bin..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\stl_function.h|227|error: no match for 'operator&lt;' in '__x &lt;
    __y'| ||=== Build finished: 1 errors, 0 warnings ===|</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  
  using namespace std;
  
  class Class1
  {
  public:
      Class1(int id);
  
  private:
      int id;
  };
  
  Class1::Class1(int id): id(id)
  {}
  
  int main()
  {
      Class1 c1(1);
  
      map&lt; Class1 , int&gt; c2int;
      c2int[c1] = 12;
  
      return 0;
  }
  </code></pre>