title: Declaring global enumerated arrays c++
body: <p>I'm working on a system of arrays to function as an inventory, I need the array to have global scope so that it can be modified throughout the program. I have it declared w/ its enumerators in a header file like so: </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #ifndef ITEMSARRAY_H
  #define ITEMSARRAY_H
  
  using namespace std;
  
  enum Weapons
  {
      LASER_RIFLE,
      LASER_SWORD,
      LASER_PISTOL,
      PLASMA_LAUNCHER,
      MAX_ITEMS
  };
  
  bool items[MAX_ITEMS];
      items[LASER_RIFLE] = true;
      items[LASER_SWORD] = false;
      items[LASER_PISTOL] = false;
      items[PLASMA_LAUNCHER] = true;
  
  
  #endif
  </code></pre>
  
  <p>however this throws me an error on the lower statements because its trying to declare it as its own array or because its trying to initialize the value to the enum.I can put it in a function and resolve this problem like so:</p>
  
  <pre><code>void defineItemArray(bool items[MAX_ITEMS])
  {
      items[LASER_RIFLE] = true;
      items[LASER_SWORD] = false;
      items[LASER_PISTOL] = false;
      items[PLASMA_LAUNCHER] = true;
  }
  </code></pre>
  
  <p>the problem with this is that is then when i try to use the function the argument items does not pull the array like so: </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include "itemsArray.h"
  
  using namespace std;
  
  void playerInventory()
  {
      defineItemArray(items);
      for (int item = 0; item &lt; MAX_ITEMS; ++item)
          if (items[item] == true)
          {
              switch (item)
              {
              case 0:
                  cout &lt;&lt; "Laser Rifle\n";
                  break;
              case 1:
                  cout &lt;&lt; "Laser Sword\n";
                  break;
              case 2:
                  cout &lt;&lt; "Laser Pistol\n";
                  break;
              case 3:
                  cout &lt;&lt; "Plasma Launcher \n";
                  break;
              default:
                  cout &lt;&lt; "Error";
                  break;
              }
          }
          else
              cout &lt;&lt; "Not in Inventory\n";
  }
  
  void playerGet()
  {
      defineItemArray(items);
      cout &lt;&lt; "You have found a Laser Sword.\n";
      cout &lt;&lt; "Laser Sword added to inventory.\n";
      items[LASER_SWORD] = true;
  }
  
  
  int main()
  {
      playerInventory();
      playerGet();
      playerInventory();
      return 0;
  }
  </code></pre>
  
  <p>the <strong>item</strong> throws an undefined error, making the function useless. I'm not sure what I'm missing, but if I can get past this roadblock i can finally have this inventory system finished. </p>