title: c++ how to remove objects from a vector in a function
body: <p>I would like to remove objects from a vector. The vector is passed by reference, and I'm lost. I have tried brickList.erase(it) and also the combination erase remove, but I can't figure out the correct expression. </p>
  
  <p>Would someone be so kind to help me on the commented line? In the general case with let's say 100 bricks with random positions.</p>
  
  <pre><code>#include "stdafx.h"
  
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  class Brick {
  private:
      int position;
  public:
      Brick(int);
      int getPosition();
  };
  Brick::Brick(int p) : position(p) {};
  int Brick::getPosition() { return position; }
  
  void removeBricks(int a, int b, std::vector&lt;Brick&gt; &amp;brickList) {
      std::vector&lt;Brick&gt;::iterator it;
      for (it = brickList.begin(); it != brickList.end(); ++it) {
          int currentPos = (*it).getPosition();
          if (currentPos &gt;= a &amp;&amp; currentPos &lt;= b) {
              // here I need help to delete objects
          }
      }
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      std::vector&lt;Brick&gt; myBricks;
      for (int i = 0; i&lt;10; ++i) {
          Brick tmp_brick(i);
          myBricks.push_back(tmp_brick);
      }
      // delete all bricks with position between 3 and 5
      removeBricks(3, 5, myBricks);
      system("pause");
      return 0;
  }
  </code></pre>