title: C++ Cant Change Object's Variables
body: <pre><code>class ship {
  public:
      int location;
      int length;
  };
  
  void createship(ship ship1, int gridsize) {             //function to set ship1's length and location
      srand(time(NULL));
      ship1.length = (int)((rand()) % gridsize) / 4 + 1;
      ship1.location = (int)(rand()) % gridsize;
  }
  
  void insertship(ship ship1, vector &lt;char&gt; grid) {           //insert ship into grid, change grid's elements from 'e' to 'f'
      for (int temp2= 0; temp2 &lt; ship1.length; temp2++) {
          grid[ship1.location + temp2] = 'f';
      }
  }
  
  int main()
  {
      int gridsize;
      cout &lt;&lt; "Gridsize: ";
      cin &gt;&gt; gridsize;
      cout &lt;&lt; "\n";
      vector &lt;char&gt; grid(gridsize, 'e');
      for (int temp3 = 0; temp3 &lt; grid.size(); temp3++) {         //cout vector grid
          cout &lt;&lt; grid[temp3];
      }
      cout &lt;&lt; "\n";
      ship* ship1 = new ship();                               //create ship1
      createship(*ship1, gridsize);
      insertship(*ship1, grid);
      cout &lt;&lt; (*ship1).length &lt;&lt; "\n";
      cout &lt;&lt; (*ship1).location &lt;&lt; "\n";
      for (int temp4 = 0; temp4 &lt; grid.size(); temp4++) {         //cout vector grid again (with ship)
          cout &lt;&lt; grid[temp4];
      }
      return 0;
  }
  </code></pre>
  
  <p>My ship1.length and ship1.location always remain as zero, even though the createship() function is supposed to change it to a random figure? Is there any mistake I made? </p>
  
  <p>Just to add more words below because stackexchange doesn't allow me to add mostly code in my question</p>