title: how to use struct in a class
body: <p>lifeform.h</p>
  
  <pre><code>class lifeform
  {
    public:
      struct item;
      void buyItem(item &amp;a);
     //code..
  }; 
  </code></pre>
  
  <p>lifeform.cpp</p>
  
  <pre><code>struct lifeform::item
  {
  std::string type,name;
  bool own;
  int value,feature;
  
      item(std::string _type,std::string _name,int _value,int _feature):type(_type), name(_name),value(_value),feature(_feature)
       {
          own=false;
       }
  };
  
  lifeform::item lBoots("boots","Leather Boots",70,20);
  
  void lifeform::buyItem(item &amp;a)
  {
  if(a.own==0)
  {
  
      inventory.push_back(a);
      a.own=1;
      addGold(-a.value);
      std::cout &lt;&lt; "Added " &lt;&lt; a.name &lt;&lt; " to the inventory.";
  
      if(a.type=="boots")
      {
          hp-=inventory[1].feature;
          inventory[1]=a;
          std::cout &lt;&lt; " ( HP + " &lt;&lt; a.feature &lt;&lt; " )\n";
          maxHp+=a.feature;
          hp+=a.feature;
      }
      }
  </code></pre>
  
  <p>there is no error so far but when i wanna use them in main.cpp like this</p>
  
  <pre><code> #include "lifeform.h"
   int main()
   {
   lifeform p;
   p.buyItem(lBoots);
   }
  </code></pre>
  
  <p>compiler says me [Error] 'lBoots' was not declared in this scope but i declared it class am i missing something?</p>