title: invalid initialization of non-const reference of type ‘std::string& from an rvalue of type ‘std::basic_string<char>
body: <pre><code>bool hasWord(int y, int x, string &amp;word) {
      if(!inRange(y, x)) return false; 
      if(board[y][x] != word[0])  return false; 
      if(word.size() == 1) return true; 
      for(int direction = 0; direction &lt; 8; direction++) {
          int nextX = x + dx[direction];
          int nextY = y + dy[direction];
          if(hasWord(nextY, nextX, word.substr(1)))  // &lt;--- This
              return true;
      }
  return false; }
  </code></pre>
  
  <p>error: invalid initialization of non-const reference of type ‘std::string&amp; {aka std::basic_string&amp;}’ from an rvalue of type ‘std::basic_string’
     if(hasWord(nextY, nextX, word.substr(1)))</p>
  
  <p>why the reason I was wrong? </p>