title: Changing a value of an element in an object that is stored in a vector in another object through an external function in C++
body: <p>So made a class called ‘Item’, and the object of that class will have a 100% condition at the start, the Player stores items (with name “apple” in this case) whenever I tell him to. In the degradeT function I want to pass the whole vector containing the items that the player has picked up by far and then change the condition of each Item in that vector by -1 through the chCond function.</p>
  
  <p>first error:</p>
  
  <blockquote>
  <pre><code>initial value of reference to non-const must be an lvalue
  </code></pre>
  </blockquote>
  
  <p>second error:</p>
  
  <blockquote>
  <pre><code>'void degradeT(std::vector&lt;Item,std::allocator&lt;_Ty&gt;&gt; &amp;)': cannot convert argument 1 from 'std::vector&lt;Item,std::allocator&lt;_Ty&gt;&gt;' to 'std::vector&lt;Item,std::allocator&lt;_Ty&gt;&gt; &amp;'
  </code></pre>
  </blockquote>
  
  <pre><code>#include "pch.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  using std::cout; using std::cin; using std::endl;
  using std::string; using std::vector; using std::to_string;
  
  class Item {
  
  private:
      string name; // Item name
      float condition; // Item condition
      bool consumable; // Is the item consumable
  public:
      Item() {}
      Item(string a, float b, bool c) { name = a; condition = b; consumable = c; }
      Item(string a, bool c) { name = a; condition = 100.f; consumable = c; }
  
      string getName() {
          return name;
      }
      float getCond() {
          return condition;
      }
      bool isCons() {
          return consumable;
      }
      void chCond(float a) { // Change Item condition
          condition += a;
      }
  };
  
  //-----------------------
  
  class Player {
  
  private:
      vector&lt;Item&gt; plItems; // Item container
  public:
      Player() {}
  
      void pickUpItem(Item a) { // Adding Items to inventory
          plItems.push_back(a);
          cout &lt;&lt; a.getName() &lt;&lt; " added to inventory!\n";
      }
      void checkItemConds() { // Checking condition of all items
          for (unsigned int a = 0, siz = plItems.size(); a &lt; siz; a++) {
              cout &lt;&lt; plItems[a].getName() &lt;&lt; "'s condition is: " &lt;&lt; plItems[a].getCond() &lt;&lt; "%\n";
          }
      }
      Item returnItem(unsigned int a) { // Return a specific Item
          return plItems[a];
      }
      int getCurInvOcc() { // Get cuurent inventory occupation
          return plItems.size();
      }
      vector&lt;Item&gt; getPlItems() { // Return the vector (Item container)
          return plItems;
      }
  };
  
  //-------------------------
  void degradeT(vector&lt;Item&gt;&amp; Itemss); // Degrade item after some time
  //-------------------------
  
  int main()
  {
      Player me; // me
      string inp; // input
      int num = 1; // apple 1, apple 2, apple 3...
  
      while (inp != "exit") {
          cin &gt;&gt; inp;
  
          if (inp == "addApple") {
              Item apple(("apple " + to_string(num)), true);
              me.pickUpItem(apple);
              num++;
          }
  
          if (inp == "checkItemConds") {
              me.checkItemConds();
          }
  
          if (inp == "timeTick") {
  
              // This doesn't have anything to do with time I just want to test the function manually
  
              degradeT(me.getPlItems());
          }
  
      }
  
      system("PAUSE");
      return 0;
  }
  
  void degradeT(vector&lt;Item&gt; &amp;Itemss) {
  
      for (unsigned int a = 0, siz = Itemss.size(); a &lt; siz; a++) {
          Itemss[a].chCond(-1);
          cout &lt;&lt; Itemss[a].getName() &lt;&lt; endl;
      }
  }
  </code></pre>