title: Declaring a variable in an if-else block in C++
body: <p>I'm trying to declare a variable in an if-else block as follows:</p>
  
  <pre><code>int main(int argc, char *argv[]) {
  
      if (argv[3] == string("simple")) {
          Player &amp; player = *get_Simple();
      } else if (argv[3] == string("counting")) {
          Player &amp; player = *get_Counting();
      } else if (argv[3] == string("competitor")) {
          Player &amp; player = *get_Competitor();
      }
  
      // More code
  }
  </code></pre>
  
  <p>But, I'm getting the following errors when I try to compile:</p>
  
  <blockquote>
    <p>driver.cpp:38: error: unused variable
    ‘player’<br> driver.cpp:40: error:
    unused variable ‘player’<br>
    driver.cpp:42: error: unused variable
    ‘player’<br> driver.cpp:45: error:
    ‘player’ was not declared in this
    scope</p>
  </blockquote>
  
  <p>Any ideas?</p>