title: C++ Program crashes when executing object functions
body: <p>Here is part of the code:</p>
  
  <pre><code>class Inventory {
      public:
          void PrintInventory();
          void AddItemToInventory();
          void UpdateItemQtyInInventory();
          void RemoveItemFromInventory();
      private:
          vector&lt;Item*&gt; inventory;
  };
  
  void Inventory::PrintInventory() {
      unsigned int i = 0;
      if (inventory.size() == 0) {
          cout &lt;&lt; "No items to print." &lt;&lt; endl;
      } else {
          for (i=0; i &lt; inventory.size(); ++i) {
              cout &lt;&lt; i &lt;&lt; " - ";
              inventory.at(i)-&gt;Print();
          }
      }
      return;
  }
  
  void Inventory::AddItemToInventory() {
      string usrInptName = "";
      string usrInptQntyStr = "";
      string usrInptPriceStr = "";
      string usrInptOptn = "default";
      istringstream inSS;
      int usrInptQnty = 0;
      int usrInptPrice = 0;
      string usrInptOther = "";
      bool valid = false;
  
      while (valid == false) {
          cout &lt;&lt; "Enter (b)ook or (p)roduce: ";
          getline(cin, usrInptOptn);
  
          if (usrInptOptn.size() == 0) {
                  continue;
          } else if (usrInptOptn.at(0) == 'p') {
              Produce* prdct;
  
              cout &lt;&lt; "Enter name of new produce: ";
              getline(cin, usrInptName);
  
              cout &lt;&lt; "Enter the price per item: $";
              getline(cin, usrInptPriceStr);
              inSS.str(usrInptPriceStr);
              inSS &gt;&gt; usrInptPrice;
              inSS.clear();
  
              cout &lt;&lt; "Enter quantity: ";
              getline(cin, usrInptQntyStr);
              inSS.str(usrInptQntyStr);
              inSS &gt;&gt; usrInptQnty;
              inSS.clear();
  
              cout &lt;&lt; "Enter expiration date: ";
              getline(cin, usrInptOther);
  
              prdct = new Produce;
              prdct-&gt;SetName(usrInptName);
              prdct-&gt;SetPrice(usrInptPrice);
              prdct-&gt;SetQuantity(usrInptQnty);
              prdct-&gt;SetExpiration(usrInptOther);
  
              inventory.push_back(prdct);
              valid = true;
  
          } else if (usrInptOptn.at(0) == 'b') {
              Book* prdct;
  
              cout &lt;&lt; "Enter name of new book: ";
              getline(cin, usrInptName);
  
              cout &lt;&lt; "Enter the price per item: $";
              getline(cin, usrInptPriceStr);
              inSS.str(usrInptPriceStr);
              inSS &gt;&gt; usrInptPrice;
              inSS.clear();
  
              cout &lt;&lt; "Enter quantity: ";
              getline(cin, usrInptQntyStr);
              inSS.str(usrInptQntyStr);
              inSS &gt;&gt; usrInptQnty;
              inSS.clear();
  
              cout &lt;&lt; "Enter Author: ";
              getline(cin, usrInptOther);
  
              prdct = new Book;
              prdct-&gt;SetName(usrInptName);
              prdct-&gt;SetPrice(usrInptPrice);
              prdct-&gt;SetQuantity(usrInptQnty);
              prdct-&gt;SetAuthor(usrInptOther);
  
              inventory.push_back(prdct);
              valid = true;
          } else {
              cout &lt;&lt; "Invalid choice\n";
          }
  
      }
  
      return;
  }
  
  Inventory* inventory;
  
  int main() {
      string usrInptOptn = "default";
  
      while (true) {
          // Get user choice
          cout &lt;&lt; "\nEnter (p)rint, (a)dd, (u)pdate, (r)emove, or (q)uit: ";
          getline(cin, usrInptOptn);
  
          // Process user choice
          if (usrInptOptn.size() == 0) {
              continue;
          } else if (usrInptOptn.at(0) == 'p') {
              inventory-&gt;PrintInventory();
          } else if (usrInptOptn.at(0) == 'a') {
              inventory-&gt;AddItemToInventory();
          } else if (usrInptOptn.at(0) == 'u') {
              inventory-&gt;UpdateItemQtyInInventory();
          } else if (usrInptOptn.at(0) == 'r') {
              inventory-&gt;RemoveItemFromInventory();
          } else if (usrInptOptn.at(0) == 'q') {
              cout &lt;&lt; "\nGood bye." &lt;&lt; endl;
              break;
          }
  
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The program crashes when it is running the functions. I don't have the slightest idea why. The AddItemtoIventory function runs through it's entirety before the program crashes while the other one ,and the others, just crashes.</p>