title: Access to a struct pointer is not permitted in a method
body: <p>So I am just making a quick game to help me understand programming in c++.
  Basically I made a pointer to a struct called player1 in the main method.
  After I initialized it and gave it some memory to use I decided to make a method to display the values of this specific pointer. Now I think this just shows that maybe I don't understand pointers like I should but When I try and access the pointer that I made in main it doesn't exist. in code i should be able to type player1->health to get the health in the method, but player1 doesn't exist in the methods scope.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  using namespace std;
  
  typedef struct enemy{
      char name[120];
      float health;
      int magic;
      int level;
  
  
  } ene;
  
  typedef struct player{
      char name[120];
      float health;
      int magic;
      int level;
      int exp;
  
  
  } play;
  
  void startGame();
  void saveGame();
  void displayHud();
  
  
  
  int main(int argc, const char * argv[]) {
      // insert code here...
      // check if there is a save game
      // check if save game
  
      // initailize the player with 100 health and magic
      play *player1;
  
      player1 = (play *) malloc(sizeof(play));
  
      player1-&gt;health = 100;
      player1-&gt;level = 0;
      player1-&gt;magic = 100;
      displayHud();
  
  
  
  
      startGame();
  
  
  
      free(player1);
      return 0;
  }
  
  
  
  void displayHud(){
      printf("Health: %d Magic: %d Exp: %d", player1-&gt;health); //Doesn't exist
  
  
  }
  </code></pre>