title: Using struct as KEY and VALUE for map. find() operation giving error
body: <p>Code in c++:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct keyInfo
  {
    string Key1; 
    string Key2; 
  
    bool keyInfo::operator &lt;(keyInfo &amp;A) const
      { return ((this-&gt;Key1&lt;A.Key1)&amp;&amp;(this-&gt;Key2&lt;A.Key2)); }
  };
  
  struct valueInfo
  { 
    int value1; 
    int value2; 
    int value3; 
  
    valueInfo(const int A,const int B,const int C) : 
      value1(A),value2(B),value3(C) {}
  };
  typedef std::map&lt;keyInfo, valueInfo&gt; MapTYPE;
  
  int main()
  {
    MapTYPE TMap;
    keyInfo K;
    K.Key1="main";
    K.Key2="i";
    valueInfo V(-2,-3322,9000);
  
    TMap.insert(MapTYPE::value_type(K,V));
    MapTYPE::iterator It1=TMap.find(K);
    It1=TMap.find(K);
    if(It1!=TMap.end())
      std::cout&lt;&lt;"Success(K): "&lt;&lt;It1-&gt;second.value2&lt;&lt;std::endl;
  
    keyInfo E;
    E.Key1="main";
    E.Key2="j";
    //TMap.insert(std::pair&lt;keyInfo,valueInfo&gt;(E,V));
    MapTYPE::iterator It2=TMap.find(E);
    if (It2!=TMap.end())
       std::cout&lt;&lt;"Success(E): "&lt;&lt;(It2-&gt;second).value3&lt;&lt;std::endl;
  
    cin.get();
    return 0;
   }
  </code></pre>
  
  <p>When I compile this code it gave me the error:</p>
  
  <blockquote>
    <p>error C2679: binary '&lt;' : no operator found which takes a right-hand operand of type 'const keyInfo1' (or there is no acceptable conversion)</p>
  </blockquote>
  
  <p>Please let me know where I'm going wrong?
  Any help is highly appreciated.
  Thanks.</p>
  
  <p>I have tried to implement own operator and used in map&lt;>, code looks as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct keyInfo
  {
    string Key1; 
    string Key2; 
  
    /*bool keyInfo::operator()(keyInfo const&amp; Left,keyInfo const&amp; Right) const{
        return ((Left.Key1&lt;Right.Key1)&amp;&amp;(Left.Key2&lt;Right.Key2));
    }*/
  };
  
  struct LessComparer{
      bool operator()(keyInfo const&amp; Left,keyInfo const&amp; Right) const{
          return !(Left.Key1==Right.Key1 &amp;&amp; Left.Key2==Right.Key2);
      }
  };
  
  struct valueInfo
  { 
    int value1; 
    int value2; 
    int value3; 
  
    valueInfo(const int A,const int B,const int C) : 
      value1(A),value2(B),value3(C) {}
  };
  typedef std::map&lt;keyInfo, valueInfo, LessComparer&gt; MapTYPE;
  
  int main()
  {
    MapTYPE TMap;
    keyInfo K;
    K.Key1="main";
    K.Key2="i";
    valueInfo V(-2,-3322,9000);
  
    TMap.insert(MapTYPE::value_type(K,V));
    MapTYPE::iterator It1=TMap.find(K);
    It1=TMap.find(K);
    if(It1!=TMap.end())
      std::cout&lt;&lt;"Success(K): "&lt;&lt;It1-&gt;second.value2&lt;&lt;std::endl;
  
    keyInfo E;
    E.Key1="main";
    E.Key2="j";
    //TMap.insert(std::pair&lt;keyInfo,valueInfo&gt;(E,V));
    MapTYPE::iterator It2=TMap.find(E);
    if (It2!=TMap.end())
       std::cout&lt;&lt;"Success(E): "&lt;&lt;(It2-&gt;second).value3&lt;&lt;std::endl;
  
    cin.get();
    return 0;
   }
  </code></pre>
  
  <p>Here I'm using operator() to return 0 iff both Key1 and Key2 of Left and Right are equal. I think this is the same way map::less works, I mean it return false only if equality condition is satisfied.</p>
  
  <p>It works fine in first case i.e. TMap.find(K) where same key is found. But during call in second case i.e. TMap.find(E) it pops up an error saying:</p>
  
  <pre><code>"Debug assertion failed"
  Expression: Invalid operator &lt;
  </code></pre>