title: How to insert struct into stl::map C++
body: <p>I am trying to use a loop to populate a map using the insert method. I have a map that I am trying to populate using this method:</p>
  
  <pre><code>void board:: insertToMap(Letter c, int num){
      this-&gt;myRackMap.insert(pair&lt;Letter, int&gt;(c, num));
  }
  </code></pre>
  
  <p>and I call this helper method in this loop within another method: </p>
  
  <pre><code>void board:: getRackAsMap(){
      for (int i = 0; i &lt; this-&gt;getMyRack().size(); ++i){
          insertToMap(this-&gt;getMyRack().at(i), this-&gt;getMyRack().at(i).readScore());
      }
  }
  //myRackMap is a map&lt;Letter, int&gt;
  //myRack is a vector&lt;Letter&gt;
  
  vector&lt;Letter&gt;&amp; board::getMyRack(){
      return this-&gt;myRack;
  }
  
  //readScore returns an Int value based on the char value of the current Letter
  </code></pre>
  
  <p>When I try to run this I get a ridiculously long error message, waaay too long to put into this. The ending line of the error message is this; however:</p>
  
  <blockquote>
    <p>"‘const Letter’ is not derived from ‘const std::multimap&lt;_Key, _Tp,
    _Compare, _Alloc>’
           { return __x &lt; __y; }"</p>
  </blockquote>
  
  <p>which led me to believe that the error is related to inserting my struct Letter into the map instead of a primitive data type. Any advice would be greatly appreciated as I am not too familiar with c++, thank you for any help you can provide!</p>
  
  <p>EDIT: here is what Letter.h looks like</p>
  
  <pre><code>struct Letter{
  private:
      char theLetter;
      int xPos;
      int yPos;
  public:
      Letter();
      Letter(char c);
      Letter(int x, int y, char c);
      void setPos(int x, int y);
      void setLetter(char c);
      int getXPos();
      int getYPos();
      char getTheLetter();
      int readScore();
  };
  </code></pre>
  
  <p>and letter.cpp</p>
  
  <pre><code>Letter:: Letter(){
      this-&gt;xPos = -1;
      this-&gt;yPos = -1;
      this-&gt;theLetter = '?';
  }
  
  Letter:: Letter(char c){
      this-&gt;xPos = -1;
      this-&gt;yPos = -1;
      this-&gt;theLetter = c;
  }
  
  Letter:: Letter(int x, int y, char c){
      this-&gt;xPos = x;
      this-&gt;yPos = y;
      this-&gt;theLetter = c;
  }
  int Letter:: getXPos(){
      return this-&gt;xPos;
  }
  int Letter:: getYPos(){
      return this-&gt;yPos; 
  } 
  char Letter:: getTheLetter(){
      return this-&gt;theLetter;
  }
  void Letter:: setPos(int x, int y){
      this-&gt;xPos = x;
      this-&gt;yPos = y;
  }
  void Letter:: setLetter(char c){
      this-&gt;theLetter = c;
  }
  int Letter:: readScore(){
      switch (this-&gt;getTheLetter()){
          case 'A':
          return 1;
          break;
      case 'B':
          return 3;
          break;
      //etc etc, returns int based on char of Letter
      }
  }
  </code></pre>